alchemy functions updated

This commit is contained in:
2024-11-10 12:14:10 +03:00
parent 1f75e49a07
commit e01a2c8afb
24 changed files with 543 additions and 389 deletions

View File

@@ -37,7 +37,10 @@ class EventBindOccupantEventMethods(MethodToEvent):
detail="This employee is not authorized to add event to this occupant",
)
occupants_build_part = BuildParts.find_one(uu_id=data.build_part_uu_id)
occupants_build_part = BuildParts.filter_one(
BuildParts.uu_id == data.build_part_uu_id,
BuildParts.active == True,
).data
if not occupants_build_part:
return JSONResponse(
content={
@@ -48,7 +51,9 @@ class EventBindOccupantEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
)
occupant_occupant_type = OccupantTypes.find_one(uu_id=data.occupant_uu_id)
occupant_occupant_type = OccupantTypes.filter_by_one(
uu_id=data.occupant_uu_id
).data
if not occupant_occupant_type:
return JSONResponse(
content={
@@ -59,8 +64,9 @@ class EventBindOccupantEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
)
events_to_add_to_occupant = Events.filter_active(
Events.uu_id.in_(list(data.event_uu_id_list))
events_to_add_to_occupant = Events.filter_all(
Events.uu_id.in_(list(data.event_uu_id_list)),
Events.active == True,
)
if not events_to_add_to_occupant.data:
return JSONResponse(
@@ -85,11 +91,11 @@ class EventBindOccupantEventMethods(MethodToEvent):
status_code=status.HTTP_401_UNAUTHORIZED,
)
occupant_to_add_event = BuildLivingSpace.find_one(
build_parts_id=occupants_build_part.id,
occupant_type=occupant_occupant_type.id,
)
occupant_to_add_event = BuildLivingSpace.filter_one(
BuildLivingSpace.build_parts_id == occupants_build_part.id,
BuildLivingSpace.occupant_type == occupant_occupant_type.id,
BuildLivingSpace.active == True,
).data
if not occupant_to_add_event:
return JSONResponse(
content={

View File

@@ -30,9 +30,12 @@ class ModulesBindOccupantEventMethods(MethodToEvent):
):
living_space = BuildLivingSpace.filter_one(
Modules.id == build_living_space_id
Modules.id == build_living_space_id,
Modules.active == True,
).data
modules = Modules.filter_one(
Modules.id == modules_id, Modules.active == True
).data
modules = Modules.filter_one(Modules.id == modules_id).data
service_build_dict = dict(build_living_space_id=living_space.id)
service_build_dict["expires_at"] = str(

View File

@@ -37,11 +37,16 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
from sqlalchemy.dialects.postgresql import insert
living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.id == build_living_space_id
)
service = Services.filter_one(Services.id == service_id)
BuildLivingSpace.id == build_living_space_id,
BuildLivingSpace.active == True,
).data
service = Services.filter_one(
Services.id == service_id,
Services.active == True,
).data
add_events_list = Service2Events.filter_all(
Service2Events.service_id == service.id
Service2Events.service_id == service.id,
Service2Events.active == True,
).data
if not add_events_list:
raise Exception(
@@ -85,10 +90,11 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
detail="Employee is not authorized to add service to any occupant",
)
occupants_build_part = BuildParts.find_one(
uu_id=data.build_part_uu_id,
build_id=token_dict.selected_occupant.build_id,
)
occupants_build_part = BuildParts.filter_one(
BuildParts.uu_id == data.build_part_uu_id,
BuildParts.build_id == token_dict.selected_occupant.build_id,
BuildParts.active == True,
).data
print("occupants_build_part", occupants_build_part)
if not occupants_build_part:
return JSONResponse(
@@ -100,7 +106,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
)
occupant_occupant_type = OccupantTypes.find_one(uu_id=data.occupant_uu_id)
occupant_occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id)
if not occupant_occupant_type:
return JSONResponse(
content={
@@ -111,7 +117,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
)
service = Services.find_one(uu_id=data.service_uu_id)
service = Services.filter_one(Services.uu_id == data.service_uu_id).data
if not service:
return JSONResponse(
content={
@@ -122,26 +128,22 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
)
default_module = Modules.find_one(module_code="USR-PUB")
add_default_service = Services.find_one(module_id=default_module.id)
service_events = Service2Events.filter_all(
Service2Events.service_id == service.id,
)
default_service_events = Service2Events.filter_all(
Service2Events.service_id == add_default_service.id,
)
add_events_list = service_events.data + default_service_events.data
if not add_events_list:
Service2Events.active == True,
).data
if not service_events:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Service has no events registered. Please contact with your manager",
)
living_space = BuildLivingSpace.find_one(
build_parts_id=occupants_build_part.id,
occupant_types_id=occupant_occupant_type.id,
person_id=token_dict.person_id,
)
living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.build_parts_id == occupants_build_part.id,
BuildLivingSpace.occupant_types_id == occupant_occupant_type.id,
BuildLivingSpace.person_id == token_dict.person_id,
BuildLivingSpace.active == True,
).data
if not living_space:
return JSONResponse(
content={
@@ -160,7 +162,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
"event_uu_id": str(service_event.event_uu_id),
"is_confirmed": True,
}
for service_event in add_events_list
for service_event in service_events
]
session_execute = Services.session.execute(
@@ -186,22 +188,13 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
def bind_services_employee(cls, service_id: int, employee_id: int):
from sqlalchemy.dialects.postgresql import insert
employee = Employees.find_or_abort(
id=employee_id,
)
service = Services.find_or_abort(
id=service_id,
)
default_module = Modules.find_one(module_code="USR-PUB")
add_default_service = Services.find_one(module_id=default_module.id)
employee = Employees.filter_by_one(id=employee_id, *Employees.valid_record_dict)
service = Services.filter_by_one(id=service_id, *Services.valid_record_dict)
service_events = Service2Events.filter_all(
Service2Events.service_id == service.id,
)
default_service_events = Service2Events.filter_all(
Service2Events.service_id == add_default_service.id,
)
add_events_list = service_events.data + default_service_events.data
if not add_events_list:
Service2Events.active == True,
).data
if not service_events:
raise Exception(
"Service has no events registered. Please contact with your manager"
)
@@ -214,7 +207,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
"event_uu_id": str(service_event.event_uu_id),
"is_confirmed": True,
}
for service_event in add_events_list
for service_event in service_events
]
session_execute = Services.session.execute(
@@ -242,7 +235,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
detail="Occupant is not authorized to add service to any employee",
)
employee = Employees.find_one(uu_id=data.employee_uu_id)
employee = Employees.filter_by_one(uu_id=data.employee_uu_id, *Employees.valid_record_dict).data
if not employee:
return JSONResponse(
content={
@@ -253,7 +246,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
)
service = Services.find_one(uu_id=data.service_uu_id)
service = Services.filter_by_one(uu_id=data.service_uu_id, *Services.valid_record_dict).data
if not service:
return JSONResponse(
content={
@@ -266,16 +259,9 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
service_events = Service2Events.filter_all(
Service2Events.service_id == service.id,
)
default_module = Modules.find_one(module_code="USR-PUB")
add_default_service = Services.find_one(module_id=default_module.id)
default_service_events = Service2Events.filter_all(
Service2Events.service_id == add_default_service.id,
)
add_events_list = service_events.data + default_service_events.data
if not add_events_list:
Service2Events.active == True,
).data
if not service_events:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail="Service has no events registered. Please contact with your manager",
@@ -289,7 +275,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
"event_uu_id": service_event.event_uu_id,
"is_confirmed": True,
}
for service_event in add_events_list
for service_event in service_events
]
session_execute = Services.session.execute(

View File

@@ -39,6 +39,7 @@ class EventsListEventMethods(MethodToEvent):
Events.filter_attr = list_options
records = Events.filter_active(
*Events.get_smart_query(list_options.query),
Events.active == True,
)
return AlchemyJsonResponse(
completed=True,
@@ -82,7 +83,7 @@ class EventsUpdateEventMethods(MethodToEvent):
@classmethod
def events_update(cls, data: CreateEvents, token_dict):
event = Events.find_one(uu_id=data.uu_id)
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict)
if not event:
raise HTTPException(
status_code=404,
@@ -112,7 +113,7 @@ class EventsPatchEventMethods(MethodToEvent):
@classmethod
def events_patch(cls, data: CreateEvents, token_dict):
event = Events.find_one(uu_id=data.uu_id)
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict)
if not event:
raise HTTPException(
status_code=404,
@@ -141,18 +142,29 @@ class EventsBindEventToOccupantMethods(MethodToEvent):
@classmethod
def bind_events_employee(cls, data: RegisterEvents2Employee, token_dict):
events = Events.filter_active(Events.uu_id.in_(data.event_id))
events = Events.filter_all(
Events.uu_id.in_(data.event_id),
*Events.valid_record_args(Events),
).data
if not events:
raise HTTPException(
status_code=401,
detail="No event found. Please contact your super user.",
)
employee = Employees.find_one(employee_uu_id=data.employee_uu_id)
employee_is_not_valid = False
employee = Employees.filter_one(
Employees.employee_uu_id == data.employee_uu_id,
*Employees.valid_record_args(Employees),
).data
if employee:
staff = Staff.find_one(id=employee.staff_id)
duties = Duties.find_one(id=staff.duties_id)
staff = Staff.filter_one(
Staff.id == employee.staff_id,
*Staff.valid_record_args(Staff),
).data
duties = Duties.filter_one(
Duties.id == staff.duties_id,
*Duties.valid_record_args(Duties),
).data
if duties.company_id not in token_dict.companies_id_list:
employee_is_not_valid = True
@@ -162,7 +174,7 @@ class EventsBindEventToOccupantMethods(MethodToEvent):
detail="This employee can not be reached by this user. Please contact your super user.",
)
for event in events.data:
for event in events:
employee = Event2Employee.find_or_create(
**token_dict.user_creds, employee_id=employee.id, event_id=event.id
)
@@ -183,21 +195,25 @@ class EventsBindEventToEmployeeMethods(MethodToEvent):
@classmethod
def bind_events_occupant(cls, data: RegisterEvents2Occupant, token_dict):
events = Events.filter_active(Events.uu_id.in_(data.event_id))
events = Events.filter_all(
Events.uu_id.in_(data.event_id),
*Events.valid_record_args(Events),
).data
if not events:
raise HTTPException(
status_code=401,
detail="No event found. Please contact your super user.",
)
occupant = BuildLivingSpace.find_one(uu_id=data.build_living_space_uu_id)
occupant_is_not_valid = False
if occupant_is_not_valid:
occupant = BuildLivingSpace.filter_one(
BuildLivingSpace.uu_id == data.build_living_space_uu_id,
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
).data
if not occupant:
raise HTTPException(
status_code=401,
detail="This occupant can not be reached by this user. Please contact your super user.",
)
for event in events.data:
for event in events:
occupant = Event2Occupant.find_or_create(
**token_dict.user_creds,
build_living_space_id=occupant.id,

View File

@@ -1,3 +1,5 @@
from typing import Union
from api_validations.validations_request import (
DepartmentsPydantic,
PatchRecord,
@@ -12,27 +14,49 @@ from api_validations.core_response import AlchemyJsonResponse
class ServicesEvents(MethodToEvent):
@classmethod
def services_list(cls, list_options: ListOptions):
def services_list(
cls,
list_options: ListOptions,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
return
@classmethod
def services_create(cls, data: DepartmentsPydantic, token_dict):
def services_create(
cls,
data: DepartmentsPydantic,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
return
@classmethod
def services_update(cls, service_uu_id: str, data: DepartmentsPydantic, token_dict):
def services_update(
cls,
service_uu_id: str,
data: DepartmentsPydantic,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
return
@classmethod
def services_patch(cls, service_uu_id: str, data: PatchRecord, token_dict):
def services_patch(
cls,
service_uu_id: str,
data: PatchRecord,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
return
@classmethod
def bind_service_to_action(cls, data, token_dict):
def bind_service_to_action(
cls, data, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
return
@classmethod
def bind_module_to_service(cls, data, token_dict):
def bind_module_to_service(
cls, data, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
return
@classmethod