auth endpoints added
This commit is contained in:
@@ -573,4 +573,3 @@ class AccountRecords(CrudCollection):
|
||||
# )
|
||||
# )
|
||||
# print("is all dues_type", payment_dict["dues_type"], paid_value)
|
||||
|
||||
|
||||
@@ -6,7 +6,8 @@ from sqlalchemy import (
|
||||
Boolean,
|
||||
BigInteger,
|
||||
Integer,
|
||||
Text, or_,
|
||||
Text,
|
||||
or_,
|
||||
)
|
||||
from sqlalchemy.orm import mapped_column, Mapped
|
||||
from Controllers.Postgres.mixin import CrudCollection
|
||||
@@ -107,7 +108,7 @@ class Addresses(CrudCollection):
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.employee_id
|
||||
== token_dict.selected_company.employee_id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
).data
|
||||
post_code_id_list = [post_code.member_id for post_code in post_code_list]
|
||||
if not post_code_id_list:
|
||||
@@ -118,7 +119,9 @@ class Addresses(CrudCollection):
|
||||
# status_code=404,
|
||||
# detail="User has no post code registered. User can not list addresses.",
|
||||
# )
|
||||
cls.pre_query = cls.filter_all(cls.post_code_id.in_(post_code_id_list), db=db_session).query
|
||||
cls.pre_query = cls.filter_all(
|
||||
cls.post_code_id.in_(post_code_id_list), db=db_session
|
||||
).query
|
||||
filter_cls = cls.filter_all(*filter_expr or [], db=db_session)
|
||||
cls.pre_query = None
|
||||
return filter_cls.data
|
||||
|
||||
@@ -244,7 +244,7 @@ class Build(CrudCollection):
|
||||
livable_parts = BuildParts.filter_all(
|
||||
BuildParts.build_id == self.id,
|
||||
BuildParts.human_livable == True,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
if not livable_parts.data:
|
||||
raise HTTPException(
|
||||
@@ -260,8 +260,7 @@ class Build(CrudCollection):
|
||||
for part in self.parts:
|
||||
building_types = {}
|
||||
build_type = BuildTypes.filter_by_one(
|
||||
system=True, id=part.build_part_type_id,
|
||||
db=db_session
|
||||
system=True, id=part.build_part_type_id, db=db_session
|
||||
).data
|
||||
if build_type.type_code in building_types:
|
||||
building_types[build_type.type_code]["list"].append(part.part_no)
|
||||
@@ -354,7 +353,9 @@ class BuildParts(CrudCollection):
|
||||
if build_type := BuildTypes.filter_by_one(
|
||||
system=True, id=self.part_type_id, db=db_session
|
||||
).data:
|
||||
return f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
|
||||
return (
|
||||
f"{str(build_type.type_name).upper()} : {str(self.part_no).upper()}"
|
||||
)
|
||||
return f"Undefined:{str(build_type.type_name).upper()}"
|
||||
|
||||
|
||||
@@ -430,7 +431,7 @@ class BuildLivingSpace(CrudCollection):
|
||||
),
|
||||
cls.start_date < formatted_date - timedelta(days=add_days),
|
||||
cls.stop_date > formatted_date + timedelta(days=add_days),
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
return living_spaces.data, living_spaces.count
|
||||
|
||||
@@ -625,4 +626,3 @@ class BuildPersonProviding(CrudCollection):
|
||||
),
|
||||
{"comment": "People providing services for building"},
|
||||
)
|
||||
|
||||
|
||||
@@ -92,6 +92,7 @@ class BuildDecisionBook(CrudCollection):
|
||||
@classmethod
|
||||
def retrieve_active_rbm(cls):
|
||||
from Schemas.building.build import Build
|
||||
|
||||
with cls.new_session() as db_session:
|
||||
related_build = Build.find_one(id=cls.build_id)
|
||||
related_date = arrow.get(related_build.build_date)
|
||||
@@ -103,7 +104,7 @@ class BuildDecisionBook(CrudCollection):
|
||||
cls.expiry_ends <= date_processed,
|
||||
cls.decision_type == "RBM",
|
||||
cls.build_id == related_build.id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
).data
|
||||
if not book:
|
||||
cls.raise_http_exception(
|
||||
@@ -220,7 +221,8 @@ class BuildDecisionBookInvitations(CrudCollection):
|
||||
first_book_invitation = BuildDecisionBookInvitations.filter_one(
|
||||
BuildDecisionBookInvitations.build_id
|
||||
== token_dict.selected_occupant.build_id,
|
||||
BuildDecisionBookInvitations.decision_book_id == selected_decision_book.id,
|
||||
BuildDecisionBookInvitations.decision_book_id
|
||||
== selected_decision_book.id,
|
||||
BuildDecisionBookInvitations.invitation_attempt == 1,
|
||||
db=db_session,
|
||||
).data
|
||||
@@ -247,11 +249,15 @@ class BuildDecisionBookInvitations(CrudCollection):
|
||||
second_book_invitation = BuildDecisionBookInvitations.filter_one_system(
|
||||
BuildDecisionBookInvitations.build_id
|
||||
== token_dict.selected_occupant.build_id,
|
||||
BuildDecisionBookInvitations.decision_book_id == selected_decision_book.id,
|
||||
BuildDecisionBookInvitations.decision_book_id
|
||||
== selected_decision_book.id,
|
||||
BuildDecisionBookInvitations.invitation_attempt == 2,
|
||||
db=db_session,
|
||||
).data
|
||||
if not valid_invite_count >= need_attend_count and not second_book_invitation:
|
||||
if (
|
||||
not valid_invite_count >= need_attend_count
|
||||
and not second_book_invitation
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"In order meeting to be held, {math.ceil(need_attend_count)} people must attend "
|
||||
@@ -336,7 +342,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
with self.new_session() as db_session:
|
||||
all_decision_book_people = self.filter_all_system(
|
||||
BuildDecisionBookPersonOccupants.invite_id == self.invite_id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
BuildDecisionBookPersonOccupants.pre_query = all_decision_book_people.query
|
||||
return BuildDecisionBookPersonOccupants.filter_all_system(
|
||||
@@ -346,8 +352,9 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
def get_occupant_types(self):
|
||||
with self.new_session() as db_session:
|
||||
if occupants := BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||
db=db_session
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id
|
||||
== self.id,
|
||||
db=db_session,
|
||||
).data:
|
||||
return occupants
|
||||
return
|
||||
@@ -355,7 +362,8 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
def check_occupant_type(self, occupant_type):
|
||||
with self.new_session() as db_session:
|
||||
book_person_occupant_type = BuildDecisionBookPersonOccupants.filter_one(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id == self.id,
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id
|
||||
== self.id,
|
||||
BuildDecisionBookPersonOccupants.occupant_type_id == occupant_type.id,
|
||||
BuildDecisionBookPersonOccupants.active == True,
|
||||
BuildDecisionBookPersonOccupants.is_confirmed == True,
|
||||
|
||||
@@ -66,13 +66,12 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
)
|
||||
list_match_company_id = []
|
||||
send_duties = Duties.filter_one(
|
||||
Duties.uu_id == data.duty_uu_id,
|
||||
db=db_session
|
||||
Duties.uu_id == data.duty_uu_id, db=db_session
|
||||
)
|
||||
send_user_duties = Duties.filter_one(
|
||||
Duties.duties_id == send_duties.id,
|
||||
Duties.company_id == token_duties_id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
if not send_user_duties:
|
||||
raise Exception(
|
||||
@@ -81,14 +80,13 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
|
||||
for company_uu_id in list(data.match_company_uu_id):
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id == company_uu_id,
|
||||
db=db_session
|
||||
Companies.uu_id == company_uu_id, db=db_session
|
||||
)
|
||||
bulk_company = RelationshipDutyCompany.filter_one(
|
||||
RelationshipDutyCompany.owner_id == token_company_id,
|
||||
RelationshipDutyCompany.relationship_type == "Bulk",
|
||||
RelationshipDutyCompany.member_id == company.id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
if not bulk_company:
|
||||
raise Exception(
|
||||
@@ -105,7 +103,7 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
parent_id=match_company_id.parent_id,
|
||||
relationship_type="Commercial",
|
||||
show_only=False,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@@ -116,13 +114,12 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
)
|
||||
list_match_company_id = []
|
||||
send_duties = Duties.filter_one(
|
||||
Duties.uu_id == data.duty_uu_id,
|
||||
db=db_session
|
||||
Duties.uu_id == data.duty_uu_id, db=db_session
|
||||
)
|
||||
send_user_duties = Duties.filter_one(
|
||||
Duties.duties_id == send_duties.id,
|
||||
Duties.company_id == token_duties_id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
if not send_user_duties:
|
||||
raise Exception(
|
||||
@@ -131,14 +128,13 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
|
||||
for company_uu_id in list(data.match_company_uu_id):
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id == company_uu_id,
|
||||
db=db_session
|
||||
Companies.uu_id == company_uu_id, db=db_session
|
||||
)
|
||||
bulk_company = RelationshipDutyCompany.filter_one(
|
||||
RelationshipDutyCompany.owner_id == token_company_id,
|
||||
RelationshipDutyCompany.relationship_type == "Bulk",
|
||||
RelationshipDutyCompany.member_id == company.id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
if not bulk_company:
|
||||
raise Exception(
|
||||
@@ -151,7 +147,7 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
Duties.init_a_company_default_duties(
|
||||
company_id=match_company_id.id,
|
||||
company_uu_id=str(match_company_id.uu_id),
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
RelationshipDutyCompany.find_or_create(
|
||||
owner_id=token_company_id,
|
||||
@@ -160,7 +156,7 @@ class RelationshipDutyCompany(CrudCollection):
|
||||
parent_id=match_company_id.parent_id,
|
||||
relationship_type="Organization",
|
||||
show_only=False,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
@@ -236,4 +232,3 @@ class Companies(CrudCollection):
|
||||
Index("_company_ndx_02", formal_name, public_name),
|
||||
{"comment": "Company Information"},
|
||||
)
|
||||
|
||||
|
||||
@@ -13,12 +13,20 @@ class Staff(CrudCollection):
|
||||
__tablename__ = "staff"
|
||||
__exclude__fields__ = []
|
||||
|
||||
staff_description: Mapped[str] = mapped_column(String, server_default="", comment="Staff Description")
|
||||
staff_name: Mapped[str] = mapped_column(String, nullable=False, comment="Staff Name")
|
||||
staff_code: Mapped[str] = mapped_column(String, nullable=False, comment="Staff Code")
|
||||
staff_description: Mapped[str] = mapped_column(
|
||||
String, server_default="", comment="Staff Description"
|
||||
)
|
||||
staff_name: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff Name"
|
||||
)
|
||||
staff_code: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff Code"
|
||||
)
|
||||
|
||||
duties_id: Mapped[int] = mapped_column(ForeignKey("duties.id"), nullable=False)
|
||||
duties_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Duty UUID")
|
||||
duties_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Duty UUID"
|
||||
)
|
||||
|
||||
__table_args__ = ({"comment": "Staff Information"},)
|
||||
|
||||
@@ -29,9 +37,13 @@ class Employees(CrudCollection):
|
||||
__exclude__fields__ = []
|
||||
|
||||
staff_id: Mapped[int] = mapped_column(ForeignKey("staff.id"))
|
||||
staff_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Staff UUID")
|
||||
staff_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff UUID"
|
||||
)
|
||||
people_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=True)
|
||||
people_uu_id: Mapped[str] = mapped_column(String, nullable=True, comment="People UUID")
|
||||
people_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=True, comment="People UUID"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("employees_ndx_00", people_id, staff_id, unique=True),
|
||||
@@ -44,10 +56,18 @@ class EmployeeHistory(CrudCollection):
|
||||
__tablename__ = "employee_history"
|
||||
__exclude__fields__ = []
|
||||
|
||||
staff_id: Mapped[int] = mapped_column(ForeignKey("staff.id"), nullable=False, comment="Staff ID")
|
||||
staff_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="Staff UUID")
|
||||
people_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=False, comment="People ID")
|
||||
people_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="People UUID")
|
||||
staff_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("staff.id"), nullable=False, comment="Staff ID"
|
||||
)
|
||||
staff_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="Staff UUID"
|
||||
)
|
||||
people_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("people.id"), nullable=False, comment="People ID"
|
||||
)
|
||||
people_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="People UUID"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("_employee_history_ndx_00", people_id, staff_id),
|
||||
@@ -67,7 +87,9 @@ class EmployeesSalaries(CrudCollection):
|
||||
Numeric(20, 6), nullable=False, comment="Net Salary"
|
||||
)
|
||||
people_id: Mapped[int] = mapped_column(ForeignKey("people.id"), nullable=False)
|
||||
people_uu_id: Mapped[str] = mapped_column(String, nullable=False, comment="People UUID")
|
||||
people_uu_id: Mapped[str] = mapped_column(
|
||||
String, nullable=False, comment="People UUID"
|
||||
)
|
||||
|
||||
__table_args__ = (
|
||||
Index("_employee_salaries_ndx_00", people_id, "expiry_starts"),
|
||||
|
||||
@@ -110,9 +110,7 @@ class Services(CrudCollection):
|
||||
def retrieve_service_via_occupant_code(cls, occupant_code):
|
||||
with cls.new_session() as db_session:
|
||||
occupant_type = OccupantTypes.filter_by_one(
|
||||
system=True,
|
||||
occupant_code=occupant_code,
|
||||
db=db_session
|
||||
system=True, occupant_code=occupant_code, db=db_session
|
||||
).data
|
||||
if not occupant_type:
|
||||
cls.raise_http_exception(
|
||||
@@ -124,8 +122,7 @@ class Services(CrudCollection):
|
||||
},
|
||||
)
|
||||
return cls.filter_one(
|
||||
cls.related_responsibility == occupant_type.occupant_code,
|
||||
db=db_session
|
||||
cls.related_responsibility == occupant_type.occupant_code, db=db_session
|
||||
).data
|
||||
|
||||
__table_args__ = ({"comment": "Services Information"},)
|
||||
|
||||
@@ -431,4 +431,3 @@ class Contracts(CrudCollection):
|
||||
Index("_contract_ndx_01", contract_code, unique=True),
|
||||
{"comment": "Contract Information"},
|
||||
)
|
||||
|
||||
|
||||
@@ -40,15 +40,19 @@ class ApiEnumDropdown(CrudCollection):
|
||||
if search := cls.filter_one_system(
|
||||
cls.enum_class.in_(["DebitTypes"]),
|
||||
cls.uu_id == search_uu_id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
).data:
|
||||
return search
|
||||
elif search_debit:
|
||||
if search := cls.filter_one(
|
||||
cls.enum_class.in_(["DebitTypes"]), cls.key == search_debit, db=db_session
|
||||
cls.enum_class.in_(["DebitTypes"]),
|
||||
cls.key == search_debit,
|
||||
db=db_session,
|
||||
).data:
|
||||
return search
|
||||
return cls.filter_all_system(cls.enum_class.in_(["DebitTypes"]), db=db_session).data
|
||||
return cls.filter_all_system(
|
||||
cls.enum_class.in_(["DebitTypes"]), db=db_session
|
||||
).data
|
||||
|
||||
@classmethod
|
||||
def get_due_types(cls):
|
||||
@@ -56,7 +60,7 @@ class ApiEnumDropdown(CrudCollection):
|
||||
if due_list := cls.filter_all_system(
|
||||
cls.enum_class == "BuildDuesTypes",
|
||||
cls.key.in_(["BDT-A", "BDT-D"]),
|
||||
db=db_session
|
||||
db=db_session,
|
||||
).data:
|
||||
return [due.uu_id.__str__() for due in due_list]
|
||||
# raise HTTPException(
|
||||
@@ -71,17 +75,19 @@ class ApiEnumDropdown(CrudCollection):
|
||||
if search := cls.filter_one_system(
|
||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
||||
cls.uu_id == search_uu_id,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
).data:
|
||||
return search
|
||||
elif search_management:
|
||||
if search := cls.filter_one_system(
|
||||
cls.enum_class.in_(["BuildDuesTypes"]),
|
||||
cls.key == search_management,
|
||||
db=db_session
|
||||
db=db_session,
|
||||
).data:
|
||||
return search
|
||||
return cls.filter_all_system(cls.enum_class.in_(["BuildDuesTypes"]), db=db_session).data
|
||||
return cls.filter_all_system(
|
||||
cls.enum_class.in_(["BuildDuesTypes"]), db=db_session
|
||||
).data
|
||||
|
||||
def get_enum_dict(self):
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user