event list token updated
This commit is contained in:
@@ -107,9 +107,9 @@ from api_events.events.company.company_staff import (
|
||||
StaffPatchEventMethod,
|
||||
)
|
||||
from api_events.events.building.building_living_spaces import (
|
||||
BuildingLivingSpacesPartsListEventMethod,
|
||||
BuildingLivingSpacesPartsCreateEventMethod,
|
||||
BuildingLivingSpacesPartsUpdateEventMethod,
|
||||
BuildingLivingSpacesListEventMethod,
|
||||
BuildingLivingSpacesCreateEventMethod,
|
||||
BuildingLivingSpacesUpdateEventMethod,
|
||||
)
|
||||
from api_events.events.decision_book.decision_book_decision_book import (
|
||||
DecisionBookListEventMethod,
|
||||
@@ -211,9 +211,9 @@ __all__ = [
|
||||
"BuildingBuildPartsCreateEventMethod",
|
||||
"BuildingBuildPartsUpdateEventMethod",
|
||||
"BuildingBuildPartsPatchEventMethod",
|
||||
"BuildingLivingSpacesPartsListEventMethod",
|
||||
"BuildingLivingSpacesPartsCreateEventMethod",
|
||||
"BuildingLivingSpacesPartsUpdateEventMethod",
|
||||
"BuildingLivingSpacesListEventMethod",
|
||||
"BuildingLivingSpacesCreateEventMethod",
|
||||
"BuildingLivingSpacesUpdateEventMethod",
|
||||
"BuildAreaListEventMethod",
|
||||
"BuildAreaCreateEventMethod",
|
||||
"BuildAreaUpdateEventMethod",
|
||||
|
||||
@@ -163,8 +163,8 @@ class AccountRecordsListEventMethods(MethodToEvent):
|
||||
.filter(*main_filters)
|
||||
).order_by(order_by_list)
|
||||
|
||||
query.limit(list_options.page_size or 5).offset(
|
||||
(list_options.page or 1 - 1) * list_options.page_size or 5
|
||||
query.limit(list_options.size or 5).offset(
|
||||
(list_options.page or 1 - 1) * list_options.size or 5
|
||||
)
|
||||
for list_of_values in query.all() or []:
|
||||
return_list.append(
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
from typing import Union
|
||||
|
||||
from api_events.events.events.events_bind_modules import ModulesBindOccupantEventMethods
|
||||
|
||||
from api_events.events.events.events_bind_services import (
|
||||
ServiceBindOccupantEventMethods,
|
||||
)
|
||||
from databases import (
|
||||
Modules,
|
||||
BuildParts,
|
||||
@@ -17,9 +20,10 @@ from api_validations.validations_request import (
|
||||
UpdateBuildLivingSpace,
|
||||
ListOptions,
|
||||
)
|
||||
from databases.sql_models.event.event import Services
|
||||
|
||||
|
||||
class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
||||
class BuildingLivingSpacesListEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "SELECT"
|
||||
__event_keys__ = {
|
||||
@@ -27,7 +31,7 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def building_build_parts_list(
|
||||
def building_live_space_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
@@ -98,7 +102,7 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
|
||||
class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||
class BuildingLivingSpacesCreateEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "CREATE"
|
||||
__event_keys__ = {
|
||||
@@ -187,13 +191,17 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
||||
last_living_space.save()
|
||||
|
||||
created_living_space.save_and_confirm()
|
||||
ModulesBindOccupantEventMethods.bind_default_module_for_first_init_occupant(
|
||||
occupants_service = Services.retrieve_service_via_occupant_code(
|
||||
occupant_code=occupant_type.occupant_code
|
||||
)
|
||||
ServiceBindOccupantEventMethods.bind_services_occupant_system(
|
||||
build_living_space_id=created_living_space.id,
|
||||
service_id=occupants_service.id,
|
||||
)
|
||||
return created_living_space
|
||||
|
||||
|
||||
class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
||||
class BuildingLivingSpacesUpdateEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "UPDATE"
|
||||
__event_keys__ = {
|
||||
@@ -273,16 +281,16 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
||||
del data_dict["build_parts_uu_id"], data_dict["life_person_uu_id"]
|
||||
|
||||
|
||||
BuildingLivingSpacesPartsListEventMethod = BuildingLivingSpacesPartsListEventMethods(
|
||||
BuildingLivingSpacesListEventMethod = BuildingLivingSpacesListEventMethods(
|
||||
action=ActionsSchema(endpoint="/building/living_space/list")
|
||||
)
|
||||
BuildingLivingSpacesPartsCreateEventMethod = (
|
||||
BuildingLivingSpacesPartsCreateEventMethods(
|
||||
BuildingLivingSpacesCreateEventMethod = (
|
||||
BuildingLivingSpacesCreateEventMethods(
|
||||
action=ActionsSchema(endpoint="/building/living_space/create")
|
||||
)
|
||||
)
|
||||
BuildingLivingSpacesPartsUpdateEventMethod = (
|
||||
BuildingLivingSpacesPartsUpdateEventMethods(
|
||||
BuildingLivingSpacesUpdateEventMethod = (
|
||||
BuildingLivingSpacesUpdateEventMethods(
|
||||
action=ActionsSchema(endpoint="/building/living_space/update")
|
||||
)
|
||||
)
|
||||
|
||||
@@ -4,12 +4,12 @@ from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
from fastapi.exceptions import HTTPException
|
||||
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from databases import (
|
||||
Modules,
|
||||
Employees,
|
||||
BuildParts,
|
||||
BuildLivingSpace,
|
||||
Service2Events,
|
||||
Services,
|
||||
OccupantTypes,
|
||||
Event2Employee,
|
||||
@@ -34,44 +34,32 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
def bind_services_occupant_system(
|
||||
cls, build_living_space_id: int, service_id: int, expires_at: str = None
|
||||
):
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == build_living_space_id,
|
||||
).data
|
||||
service = Services.filter_one(Services.id == service_id).data
|
||||
add_events_list = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
).data
|
||||
if not service:
|
||||
print("Service is not valid. Service can not be binded")
|
||||
return
|
||||
|
||||
if not living_space:
|
||||
print("Living Space is not valid. Service is not binded")
|
||||
return
|
||||
if not add_events_list:
|
||||
print(f"Service has no events registered. Please contact with your manager")
|
||||
return
|
||||
|
||||
event_ids_list = [
|
||||
{
|
||||
"build_living_space_id": living_space.id,
|
||||
"build_living_space_uu_id": str(living_space.uu_id),
|
||||
"event_id": service_event.event_id,
|
||||
"event_uu_id": str(service_event.event_uu_id),
|
||||
"is_confirmed": True,
|
||||
"expiry_ends": str(expires_at) if expires_at else "2099-12-31 03:00:00",
|
||||
}
|
||||
for service_event in add_events_list
|
||||
]
|
||||
if expires_at:
|
||||
expires_at = str(system_arrow.get(expires_at))
|
||||
else:
|
||||
expires_at = str(system_arrow.get(living_space.expiry_ends))
|
||||
|
||||
session_execute = Services.session.execute(
|
||||
insert(Event2Occupant)
|
||||
.values(event_ids_list)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=["build_living_space_id", "event_id"],
|
||||
)
|
||||
occupants_event = Event2Occupant.find_or_create(
|
||||
event_service_id=service.id,
|
||||
event_service_uu_id=str(service.uu_id),
|
||||
build_living_space_id=living_space.id,
|
||||
build_living_space_uu_id=str(living_space.uu_id),
|
||||
expiry_ends=expires_at,
|
||||
)
|
||||
count_row = session_execute.rowcount
|
||||
print(f"{count_row} events are added to occupant {str(living_space.uu_id)}")
|
||||
Services.save()
|
||||
occupants_event.save_and_confirm()
|
||||
print(f"{service.service_name} is added to occupant {str(living_space.uu_id)}")
|
||||
|
||||
@classmethod
|
||||
def bind_services_occupant(
|
||||
@@ -126,14 +114,14 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
).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",
|
||||
)
|
||||
# service_events = Service2Events.filter_all(
|
||||
# Service2Events.service_id == service.id,
|
||||
# ).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.filter_one(
|
||||
BuildLivingSpace.build_parts_id == occupants_build_part.id,
|
||||
@@ -150,27 +138,27 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
event_ids_list = [
|
||||
{
|
||||
"build_living_space_id": living_space.id,
|
||||
"build_living_space_uu_id": str(living_space.uu_id),
|
||||
"event_id": service_event.event_id,
|
||||
"event_uu_id": str(service_event.event_uu_id),
|
||||
"is_confirmed": True,
|
||||
}
|
||||
for service_event in service_events
|
||||
]
|
||||
|
||||
session_execute = Services.session.execute(
|
||||
insert(Event2Occupant)
|
||||
.values(event_ids_list)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=["employee_id", "event_id"],
|
||||
)
|
||||
)
|
||||
count_row = session_execute.rowcount
|
||||
print(f"{count_row} events are added to employee {str(living_space.uu_id)}")
|
||||
Services.save()
|
||||
# event_ids_list = [
|
||||
# {
|
||||
# "build_living_space_id": living_space.id,
|
||||
# "build_living_space_uu_id": str(living_space.uu_id),
|
||||
# "event_id": service_event.event_id,
|
||||
# "event_uu_id": str(service_event.event_uu_id),
|
||||
# "is_confirmed": True,
|
||||
# }
|
||||
# for service_event in service_events
|
||||
# ]
|
||||
#
|
||||
# session_execute = Services.session.execute(
|
||||
# insert(Event2Occupant)
|
||||
# .values(event_ids_list)
|
||||
# .on_conflict_do_nothing(
|
||||
# index_elements=["employee_id", "event_id"],
|
||||
# )
|
||||
# )
|
||||
# count_row = session_execute.rowcount
|
||||
# print(f"{count_row} events are added to employee {str(living_space.uu_id)}")
|
||||
# Services.save()
|
||||
|
||||
|
||||
class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
@@ -182,44 +170,50 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
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
|
||||
).data
|
||||
service = Services.filter_by_one(
|
||||
id=service_id, **Services.valid_record_dict
|
||||
).data
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
).data
|
||||
if not service_events:
|
||||
raise Exception(
|
||||
"Service has no events registered. Please contact with your manager"
|
||||
)
|
||||
if not service:
|
||||
print("Service is not valid. Service can not be binded")
|
||||
return
|
||||
|
||||
event_ids_list = [
|
||||
{
|
||||
"employee_id": employee_id,
|
||||
"employee_uu_id": str(employee.uu_id),
|
||||
"event_id": service_event.event_id,
|
||||
"event_uu_id": str(service_event.event_uu_id),
|
||||
"is_confirmed": True,
|
||||
}
|
||||
for service_event in service_events
|
||||
]
|
||||
if not employee:
|
||||
print("Employee is not valid. Service is not binded")
|
||||
return
|
||||
|
||||
session_execute = Services.session.execute(
|
||||
insert(Event2Employee)
|
||||
.values(event_ids_list)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=["employee_id", "event_id"],
|
||||
)
|
||||
)
|
||||
count_row = session_execute.rowcount
|
||||
print(f"{count_row} events are added to employee {employee.uu_id}")
|
||||
for service_event in service_events:
|
||||
service_event.save_and_confirm()
|
||||
# service_events = Service2Events.filter_all(
|
||||
# Service2Events.service_id == service.id,
|
||||
# ).data
|
||||
# if not service_events:
|
||||
# raise Exception(
|
||||
# "Service has no events registered. Please contact with your manager"
|
||||
# )
|
||||
|
||||
# event_ids_list = [
|
||||
# {
|
||||
# "employee_id": employee_id,
|
||||
# "employee_uu_id": str(employee.uu_id),
|
||||
# "event_id": service_event.event_id,
|
||||
# "event_uu_id": str(service_event.event_uu_id),
|
||||
# "is_confirmed": True,
|
||||
# }
|
||||
# for service_event in service_events
|
||||
# ]
|
||||
#
|
||||
# session_execute = Services.session.execute(
|
||||
# insert(Event2Employee)
|
||||
# .values(event_ids_list)
|
||||
# .on_conflict_do_nothing(
|
||||
# index_elements=["employee_id", "event_id"],
|
||||
# )
|
||||
# )
|
||||
# count_row = session_execute.rowcount
|
||||
# print(f"{count_row} events are added to employee {employee.uu_id}")
|
||||
# for service_event in service_events:
|
||||
# service_event.save_and_confirm()
|
||||
|
||||
@classmethod
|
||||
def bind_services_employee_super_user(
|
||||
@@ -227,8 +221,6 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
data: RegisterServices2Employee,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
|
||||
if isinstance(token_dict, OccupantTokenObject):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
@@ -261,52 +253,61 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
service_events = Service2Events.filter_all(
|
||||
Service2Events.service_id == service.id,
|
||||
).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",
|
||||
)
|
||||
|
||||
event_ids_list = [
|
||||
{
|
||||
"employee_id": employee.id,
|
||||
"employee_uu_id": employee.uu_id,
|
||||
"event_id": service_event.event_id,
|
||||
"event_uu_id": service_event.event_uu_id,
|
||||
"is_confirmed": True,
|
||||
}
|
||||
for service_event in service_events
|
||||
]
|
||||
|
||||
session_execute = Services.session.execute(
|
||||
insert(Event2Employee)
|
||||
.values(event_ids_list)
|
||||
.on_conflict_do_nothing(
|
||||
index_elements=["employee_id", "event_id"],
|
||||
)
|
||||
)
|
||||
count_row = session_execute.rowcount
|
||||
if not count_row:
|
||||
Services.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": False,
|
||||
"message": "No events are added to employee",
|
||||
"data": {},
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": f"{count_row} events are added to employee",
|
||||
"data": {},
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
event_of_employee = Event2Employee.find_or_create(
|
||||
event_service_id=service.id,
|
||||
event_service_uu_id=str(service.uu_id),
|
||||
employee_id=employee.id,
|
||||
employee_uu_id=str(employee.uu_id),
|
||||
)
|
||||
event_of_employee.save_and_confirm()
|
||||
print(f"{service.service_name} is added to employee {str(employee.uu_id)}")
|
||||
|
||||
# service_events = Service2Events.filter_all(
|
||||
# Service2Events.service_id == service.id,
|
||||
# ).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",
|
||||
# )
|
||||
#
|
||||
# event_ids_list = [
|
||||
# {
|
||||
# "employee_id": employee.id,
|
||||
# "employee_uu_id": employee.uu_id,
|
||||
# "event_id": service_event.event_id,
|
||||
# "event_uu_id": service_event.event_uu_id,
|
||||
# "is_confirmed": True,
|
||||
# }
|
||||
# for service_event in service_events
|
||||
# ]
|
||||
#
|
||||
# session_execute = Services.session.execute(
|
||||
# insert(Event2Employee)
|
||||
# .values(event_ids_list)
|
||||
# .on_conflict_do_nothing(
|
||||
# index_elements=["employee_id", "event_id"],
|
||||
# )
|
||||
# )
|
||||
# count_row = session_execute.rowcount
|
||||
# if not count_row:
|
||||
# Services.save()
|
||||
# return JSONResponse(
|
||||
# content={
|
||||
# "completed": False,
|
||||
# "message": "No events are added to employee",
|
||||
# "data": {},
|
||||
# },
|
||||
# status_code=status.HTTP_200_OK,
|
||||
# )
|
||||
# return JSONResponse(
|
||||
# content={
|
||||
# "completed": True,
|
||||
# "message": f"{count_row} events are added to employee",
|
||||
# "data": {},
|
||||
# },
|
||||
# status_code=status.HTTP_200_OK,
|
||||
# )
|
||||
|
||||
|
||||
ServiceBindOccupantEventMethod = ServiceBindOccupantEventMethods(
|
||||
|
||||
@@ -9,7 +9,6 @@ class AuthDefaultEventBlock(AddEventFunctionality):
|
||||
{"function_code": "cee96b9b-8487-4e9f-aaed-2e8c79687bf9"},
|
||||
{"function_code": "48379bb2-ba81-4d8e-a9dd-58837cfcbf67"},
|
||||
{"function_code": "f09f7c1a-bee6-4e32-8444-962ec8f39091"},
|
||||
{"function_code": "87a15ade-3474-4206-b574-bbf8580cbb14"},
|
||||
{"function_code": "c519f9af-92e1-47b2-abf7-5a3316d075f7"},
|
||||
{"function_code": "8b586848-2fb3-4161-abbe-642157eec7ce"},
|
||||
{"function_code": "5cc22e4e-a0f7-4077-be41-1871feb3dfd1"},
|
||||
|
||||
Reference in New Issue
Block a user