alchemy functions updated
This commit is contained in:
@@ -13,7 +13,7 @@ class ActionsSchema(ABC):
|
||||
def retrieve_action_from_endpoint(self):
|
||||
from databases import EndpointRestriction
|
||||
|
||||
endpoint_restriction = EndpointRestriction.filter_all(
|
||||
endpoint_restriction = EndpointRestriction.filter_one(
|
||||
EndpointRestriction.endpoint_name.ilike(f"%{self.endpoint}%")
|
||||
).get(1)
|
||||
if not endpoint_restriction:
|
||||
|
||||
@@ -421,7 +421,7 @@ class AddressPostCodeListEventMethods(MethodToEvent):
|
||||
records = AddressPostcode.filter_all(
|
||||
*Addresses.get_smart_query(list_options.query),
|
||||
*Addresses.valid_record_args(AddressPostcode),
|
||||
)
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="List Address records",
|
||||
|
||||
@@ -559,7 +559,7 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
||||
):
|
||||
token_refresher = UsersTokens.filter_by_one(
|
||||
token=data.refresh_token, domain=data.domain, *UsersTokens.valid_record_dict
|
||||
)
|
||||
).data
|
||||
if not token_refresher:
|
||||
return JSONResponse(
|
||||
content={"completed": False, "message": "Invalid data", "data": {}},
|
||||
|
||||
@@ -188,13 +188,13 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
elif token_user.user_type == 2:
|
||||
occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id)
|
||||
occupant_type = OccupantTypes.filter_by_one(uu_id=data.occupant_uu_id).data
|
||||
if not occupant_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Occupant Type is not found",
|
||||
)
|
||||
build_part = BuildParts.filter_by_one(uu_id=data.build_part_uu_id)
|
||||
build_part = BuildParts.filter_by_one(uu_id=data.build_part_uu_id).data
|
||||
if not build_part:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
|
||||
@@ -49,7 +49,7 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
||||
),
|
||||
*BuildLivingSpace.get_smart_query(smart_query=list_options.query),
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
)
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Building Living Spaces are listed successfully",
|
||||
|
||||
@@ -134,7 +134,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
occupant_manager = OccupantTypes.filter_by_one(
|
||||
occupant_category_type="BU", occupant_code="BU-MNG"
|
||||
)
|
||||
).data
|
||||
if not token_dict.selected_occupant.occupant_type_id == occupant_manager.id:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_403_FORBIDDEN,
|
||||
|
||||
@@ -281,6 +281,7 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
|
||||
|
||||
build_parts_of_token = BuildParts.filter_all(
|
||||
BuildParts.build_id == token_dict.selected_occupant.build_id,
|
||||
*BuildParts.valid_record_args(BuildParts)
|
||||
).data
|
||||
selected_living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.uu_id == data.build_living_space_uu_id,
|
||||
|
||||
@@ -136,8 +136,8 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
|
||||
# Get all the parts of the building that is occupant in token
|
||||
build_parts = BuildParts.filter_all(
|
||||
BuildParts.build_id == occupant_building.id, BuildParts.active == True
|
||||
).data
|
||||
BuildParts.build_id == occupant_building.id, *BuildParts.valid_record_args(BuildParts)
|
||||
)
|
||||
|
||||
# Get all build living spaces that is found in building with distinct person id
|
||||
occupants = OccupantTypes.filter_all(system=True)
|
||||
@@ -217,8 +217,8 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
|
||||
manager_living_spaces = BuildLivingSpace.filter_all(
|
||||
BuildLivingSpace.person_id == token_dict.person_id,
|
||||
BuildLivingSpace.active == True,
|
||||
).data
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
)
|
||||
manager_people = BuildDecisionBookPerson.filter_all(
|
||||
BuildDecisionBookPerson.invite_id == book_invitation.id,
|
||||
BuildDecisionBookPerson.build_living_space_id.in_(
|
||||
@@ -227,12 +227,12 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
|
||||
for manager_living_space in manager_living_spaces.data
|
||||
]
|
||||
),
|
||||
BuildLivingSpace.active == True,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
)
|
||||
manager_people_occupants = BuildDecisionBookPersonOccupants.filter_all(
|
||||
BuildDecisionBookPersonOccupants.build_decision_book_person_id
|
||||
== manager_people.get(1).id,
|
||||
BuildDecisionBookPersonOccupants.active == True,
|
||||
*BuildDecisionBookPersonOccupants.valid_record_args(BuildDecisionBookPersonOccupants)
|
||||
)
|
||||
manager_people_occupants.query.delete()
|
||||
manager_people.query.delete()
|
||||
|
||||
@@ -66,7 +66,7 @@ class EventBindOccupantEventMethods(MethodToEvent):
|
||||
|
||||
events_to_add_to_occupant = Events.filter_all(
|
||||
Events.uu_id.in_(list(data.event_uu_id_list)),
|
||||
Events.active == True,
|
||||
*Events.valid_record_args(Events)
|
||||
)
|
||||
if not events_to_add_to_occupant.data:
|
||||
return JSONResponse(
|
||||
|
||||
@@ -38,15 +38,15 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
|
||||
living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == build_living_space_id,
|
||||
BuildLivingSpace.active == True,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
).data
|
||||
service = Services.filter_one(
|
||||
Services.id == service_id,
|
||||
Services.active == True,
|
||||
*Services.valid_record_args(Services)
|
||||
).data
|
||||
add_events_list = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
Service2Events.active == True,
|
||||
*Service2Events.valid_record_args(Service2Events)
|
||||
).data
|
||||
if not add_events_list:
|
||||
raise Exception(
|
||||
@@ -106,7 +106,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
occupant_occupant_type = OccupantTypes.filter_by_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={
|
||||
@@ -130,7 +130,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
Service2Events.active == True,
|
||||
Service2Events.valid_record_args(Service2Events),
|
||||
).data
|
||||
if not service_events:
|
||||
raise HTTPException(
|
||||
@@ -142,7 +142,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
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,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace)
|
||||
).data
|
||||
if not living_space:
|
||||
return JSONResponse(
|
||||
@@ -188,11 +188,11 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
def bind_services_employee(cls, service_id: int, employee_id: int):
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
employee = Employees.filter_by_one(id=employee_id, *Employees.valid_record_dict)
|
||||
service = Services.filter_by_one(id=service_id, *Services.valid_record_dict)
|
||||
employee = Employees.filter_by_one(id=employee_id, *Employees.valid_record_dict).data
|
||||
service = Services.filter_by_one(id=service_id, *Services.valid_record_dict).data
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
Service2Events.active == True,
|
||||
*Service2Events.valid_record_args(Service2Events),
|
||||
).data
|
||||
if not service_events:
|
||||
raise Exception(
|
||||
@@ -263,7 +263,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
Service2Events.active == True,
|
||||
*Service2Events.valid_record_args(Service2Events)
|
||||
).data
|
||||
if not service_events:
|
||||
raise HTTPException(
|
||||
|
||||
@@ -83,7 +83,7 @@ class EventsUpdateEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def events_update(cls, data: CreateEvents, token_dict):
|
||||
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict)
|
||||
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict).data
|
||||
if not event:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
@@ -113,7 +113,7 @@ class EventsPatchEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def events_patch(cls, data: CreateEvents, token_dict):
|
||||
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict)
|
||||
event = Events.filter_by_one(uu_id=data.uu_id, *Events.valid_record_dict).data
|
||||
if not event:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
|
||||
@@ -60,7 +60,7 @@ class UserListEventMethods(MethodToEvent):
|
||||
records = Users.filter_all(
|
||||
*Users.get_smart_query(list_options.query),
|
||||
*Users.valid_record_args(Users),
|
||||
)
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Users are listed successfully",
|
||||
|
||||
Reference in New Issue
Block a user