wag-managment-api-service-v.../api_events/events/events/events_bind_modules.py

88 lines
2.5 KiB
Python

import typing
from databases import (
Modules,
BuildLivingSpace,
)
from api_validations.validations_request import (
RegisterModules2Occupant,
RegisterModules2Employee,
)
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_events.events.events.events_bind_services import (
ServiceBindOccupantEventMethods,
)
from api_library.date_time_actions.date_functions import system_arrow
from api_validations.core_response import AlchemyJsonResponse
class ModulesBindOccupantEventMethods(MethodToEvent):
event_type = "UPDATE"
__event_keys__ = {
"": "modules_bind_occupant",
}
@classmethod
def modules_bind_occupant_system(
cls, build_living_space_id: int, modules_id: int, expires_at: str = None
):
living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.id == build_living_space_id,
).data
modules = Modules.filter_one(Modules.id == modules_id).data
if not living_space or not modules:
print(f"Giving living Space or Modules: {modules.module_name} not found")
return
service_build_dict = dict(build_living_space_id=living_space.id)
if expires_at:
service_build_dict["expires_at"] = str(system_arrow.get(expires_at))
else:
service_build_dict["expires_at"] = str(
system_arrow.get(living_space.expiry_ends)
)
for service in modules.retrieve_services():
ServiceBindOccupantEventMethods.bind_services_occupant_system(
**service_build_dict,
service_id=service.id,
)
BuildLivingSpace.save()
return True
@classmethod
def modules_bind_occupant(
cls,
data: RegisterModules2Occupant,
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
):
return
class ModulesBindEmployeeEventMethods(MethodToEvent):
event_type = "UPDATE"
__event_keys__ = {
"": "modules_bind_employee",
}
@classmethod
def modules_bind_employee(
cls,
data: RegisterModules2Employee,
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
):
return
ModulesBindOccupantEventMethod = ModulesBindOccupantEventMethods(
action=ActionsSchema(endpoint="/bind/modules/occupant")
)
ModulesBindEmployeeEventMethod = ModulesBindEmployeeEventMethods(
action=ActionsSchema(endpoint="/bind/modules/employee")
)