events imports are checked
This commit is contained in:
@@ -587,27 +587,26 @@ class BuildLivingSpace(CrudCollection):
|
||||
data: dict,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
from database_sql_models import Services, OccupantTypes
|
||||
from events.events_bind_services import ServiceBindOccupantEventMethods
|
||||
from databases import Services, OccupantTypes
|
||||
from api_events.events.events.events_bind_services import ServiceBindOccupantEventMethods
|
||||
|
||||
created_living_space = BuildLivingSpace.find_or_create(**data)
|
||||
if not created_living_space.is_found:
|
||||
occupant_type = OccupantTypes.find_one(
|
||||
uu_id=created_living_space.occupant_type_uu_id
|
||||
)
|
||||
related_service = Services.find_one(
|
||||
active=True,
|
||||
related_responsibility=occupant_type.occupant_code,
|
||||
)
|
||||
if not related_service:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||
detail="Service is not found in database. Re-enter service record then try again.",
|
||||
)
|
||||
ServiceBindOccupantEventMethods.bind_services_occupant_system(
|
||||
service_id=related_service.id,
|
||||
build_living_space_id=created_living_space.id,
|
||||
occupant_type = OccupantTypes.find_one(
|
||||
uu_id=created_living_space.occupant_type_uu_id
|
||||
)
|
||||
related_service = Services.find_one(
|
||||
active=True,
|
||||
related_responsibility=occupant_type.occupant_code,
|
||||
)
|
||||
if not related_service:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||
detail="Service is not found in database. Re-enter service record then try again.",
|
||||
)
|
||||
ServiceBindOccupantEventMethods.bind_services_occupant_system(
|
||||
service_id=related_service.id,
|
||||
build_living_space_id=created_living_space.id,
|
||||
)
|
||||
return created_living_space
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -426,7 +426,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
||||
build_living_space_id=related_living_space.id,
|
||||
service_id=related_service.id,
|
||||
expires_at=str(
|
||||
DateTimeLocal.get(str(decision_book.meeting_date)).shift(
|
||||
DateTimeLocal.get(decision_book.meeting_date).shift(
|
||||
days=15
|
||||
)
|
||||
),
|
||||
|
||||
@@ -344,15 +344,17 @@ class Companies(CrudCollection, SelectAction):
|
||||
|
||||
@classmethod
|
||||
def create_action(cls, data: InsertCompany, token: EmployeeTokenObject):
|
||||
from database_sql_models import Addresses, Duties
|
||||
from databases import Addresses, Duties
|
||||
|
||||
data_dict = data.model_dump()
|
||||
if cls.find_one(tax_no=str(data.tax_no).strip()):
|
||||
if cls.filter_one(cls.tax_no==str(data.tax_no).strip()):
|
||||
raise Exception(
|
||||
"Company already exists. Please ask supervisor to make company visible for your duty."
|
||||
)
|
||||
|
||||
official_address = Addresses.find_one(uu_id=data.official_address_uu_id)
|
||||
official_address = Addresses.filter_one(
|
||||
Addresses.uu_id==data.official_address_uu_id
|
||||
)
|
||||
if not official_address:
|
||||
raise HTTPException(
|
||||
status_code=400,
|
||||
|
||||
@@ -53,6 +53,19 @@ class Modules(CrudCollection):
|
||||
module_layer = mapped_column(Integer, nullable=False, comment="Module Layer")
|
||||
is_default_module = mapped_column(Boolean, server_default="0")
|
||||
|
||||
def retrieve_services(self):
|
||||
services = Services.filter_all(Services.module_id == self.id)
|
||||
if not services.count:
|
||||
self.raise_http_exception(
|
||||
status_code="HTTP_404_NOT_FOUND",
|
||||
error_case="RECORD_NOT_FOUND",
|
||||
message=f"No services found for this module : {str(self.uu_id)}",
|
||||
data={
|
||||
"module_uu_id": str(self.uu_id),
|
||||
},
|
||||
)
|
||||
return services.data
|
||||
|
||||
__table_args__ = ({"comment": "Modules Information"},)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from api_validations.validations_request import ListOptions
|
||||
from databases.sql_models.response_model import AlchemyResponse
|
||||
from databases.sql_models.postgres_database import Base
|
||||
|
||||
@@ -19,6 +20,7 @@ class FilterAttributes:
|
||||
|
||||
pre_query = None # The query to use before the filtering such as: query = cls.query.filter_by(active=True)
|
||||
filter_attr = None # The filter attributes to use in the model.
|
||||
FilterModel: ListOptions = ListOptions
|
||||
|
||||
def flush(self):
|
||||
"""Flush the current session."""
|
||||
@@ -101,14 +103,16 @@ class FilterAttributes:
|
||||
return arg[0]
|
||||
|
||||
@classmethod
|
||||
def filter_by_all(cls, **kwargs):
|
||||
def filter_by_all(cls, **kwargs):
|
||||
"""
|
||||
Filters all the records regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
filter_list = cls.get_filter_attributes()
|
||||
query = cls._query().filter_by(**kwargs)
|
||||
data = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data, first=False)
|
||||
if cls.filter_attr:
|
||||
filter_list = cls.get_filter_attributes()
|
||||
data_query = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data_query, first=False)
|
||||
return AlchemyResponse(query=query, first=False)
|
||||
|
||||
@classmethod
|
||||
def filter_by_one(cls, **kwargs):
|
||||
@@ -123,17 +127,18 @@ class FilterAttributes:
|
||||
"""
|
||||
Filters all the records regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
filter_list = cls.get_filter_attributes()
|
||||
query = cls._query()
|
||||
data = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data, first=False)
|
||||
query = cls._query().filter(*args)
|
||||
if cls.filter_attr:
|
||||
filter_list = cls.get_filter_attributes()
|
||||
data_query = cls.add_query_to_filter(query, filter_list)
|
||||
return AlchemyResponse(query=data_query, first=False)
|
||||
return AlchemyResponse(query=query, first=False)
|
||||
|
||||
@classmethod
|
||||
def filter_one(cls, *args, expired: bool = False):
|
||||
"""
|
||||
Filters one record regardless of is_deleted, is_confirmed.
|
||||
"""
|
||||
|
||||
arg = cls.get_not_expired_query_arg(args, expired=expired)
|
||||
query = cls._query().filter(*arg)
|
||||
return AlchemyResponse(query=query, first=True)
|
||||
|
||||
Reference in New Issue
Block a user