events imports are checked

This commit is contained in:
2024-11-08 15:05:12 +03:00
parent 643d6d8f65
commit a5b1e0b2f4
71 changed files with 2517 additions and 312 deletions

View File

@@ -1,8 +1,11 @@
from typing import Union
from fastapi import status
from fastapi.responses import JSONResponse
from validations import InsertCompanyDuty
from validations.root_validates import PatchRecord, ListOptions
from api_validations.validations_request import (
InsertCompanyDuty, PatchRecord, ListOptions
)
from databases import Duty
@@ -19,7 +22,9 @@ class DutyListEventMethods(MethodToEvent):
}
@classmethod
def duty_list(cls, list_options: ListOptions, token_dict):
def duty_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
records = Duty.filter_active(
*Duty.get_smart_query(list_options.query),
)
@@ -36,8 +41,11 @@ class DutyCreateEventMethods(MethodToEvent):
}
@classmethod
def duty_create(cls, data: InsertCompanyDuty, token_dict):
def duty_create(
cls, data: InsertCompanyDuty, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
created_duty = Duty.find_or_create(**data.excluded_dump())
Duty.save()
return JSONResponse(
content={
"completed": True,
@@ -56,7 +64,7 @@ class DutyUpdateEventMethods(MethodToEvent):
}
@classmethod
def duty_update(cls, company_uu_id: str, data, token_dict):
def duty_update(cls, company_uu_id: str, data, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]):
find_one_company = Duty.find_one_or_abort(uu_id=company_uu_id)
access_authorized_company = Duty.select_action(
duty_id=getattr(token_dict, "duty_id", 5), # ?
@@ -65,6 +73,7 @@ class DutyUpdateEventMethods(MethodToEvent):
if access_authorized_company.count:
data_dict = data.excluded_dump()
updated_company = find_one_company.update(**data_dict)
Duty.save()
return JSONResponse(
content={
"completed": True,
@@ -95,15 +104,9 @@ class DutyPatchEventMethods(MethodToEvent):
)
if access_authorized_company.count:
action = data.excluded_dump()
find_one_company.active = bool(
action.get("active", find_one_company.active)
)
find_one_company.is_confirmed = bool(
action.get("confirm", find_one_company.is_confirmed)
)
find_one_company.deleted = bool(
action.get("delete", find_one_company.deleted)
)
find_one_company.active = bool(action.get("active", find_one_company.active))
find_one_company.is_confirmed = bool(action.get("confirm", find_one_company.is_confirmed))
find_one_company.deleted = bool(action.get("delete", find_one_company.deleted))
find_one_company.save()
return JSONResponse(
content={