services are checked

This commit is contained in:
2024-11-08 17:14:02 +03:00
parent a5b1e0b2f4
commit c5b771e5cb
82 changed files with 1720 additions and 869 deletions

View File

@@ -93,7 +93,7 @@ class CompanyUpdateEventMethods(MethodToEvent):
@classmethod
def company_update(cls, company_uu_id: str, data: UpdateCompany, token_dict):
find_one_company = Companies.filter_one(Companies.uu_id==company_uu_id)
find_one_company = Companies.filter_one(Companies.uu_id == company_uu_id)
access_authorized_company = Companies.select_action(
duty_id=getattr(token_dict, "duty_id", 5),
filter_expr=[Companies.id == token_dict.get("")],

View File

@@ -25,12 +25,14 @@ class DepartmentListEventMethods(MethodToEvent):
@classmethod
def department_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
list_options: ListOptions,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
Departments.filter_attr = list_options
records = Departments.filter_active(
*Departments.get_smart_query(smart_query=list_options.query),
Departments.company_id == token_dict.selected_company.company_id
Departments.company_id == token_dict.selected_company.company_id,
)
return return_json_response_from_alchemy(
response=records, pagination=list_options
@@ -81,7 +83,7 @@ class DepartmentUpdateEventMethods(MethodToEvent):
def department_update(
cls, company_uu_id: str, data: DepartmentsPydantic, token_dict
):
find_one_company = Departments.filter_one(Departments.uu_id==company_uu_id)
find_one_company = Departments.filter_one(Departments.uu_id == company_uu_id)
access_authorized_company = Departments.select_action(
duty_id=getattr(token_dict, "duty_id", 5),
filter_expr=[Departments.id == token_dict.get("")],

View File

@@ -17,7 +17,6 @@ from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
class DutiesListEventMethods(MethodToEvent):
event_type = "SELECT"
@@ -27,12 +26,14 @@ class DutiesListEventMethods(MethodToEvent):
@classmethod
def duties_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
list_options: ListOptions,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
Duties.filter_attr = list_options
records = Duties.filter_all(
*Duties.get_smart_query(smart_query=list_options.query),
Duties.company_id == token_dict.selected_company.company_id
Duties.company_id == token_dict.selected_company.company_id,
)
return {
"completed": True if records.count else False,
@@ -50,10 +51,12 @@ class DutiesGetByUUIDEventMethods(MethodToEvent):
@classmethod
def duties_get_by_uuid(
cls, data: SelectDuties, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
data: SelectDuties,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
duty = Duty.filter_one(Duty.uu_id==data.duty_uu_id).data
duty = Duty.filter_one(Duty.uu_id == data.duty_uu_id).data
if not duty:
return JSONResponse(
content={
@@ -93,10 +96,12 @@ class DutiesCreateEventMethods(MethodToEvent):
@classmethod
def duties_create(
cls, data: InsertDuties, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
data: InsertDuties,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
duty = Duty.filter_one(Duty.uu_id==data.duties_uu_id).data
department = Departments.filter_one(Duty.uu_id==data.department_uu_id).data
duty = Duty.filter_one(Duty.uu_id == data.duties_uu_id).data
department = Departments.filter_one(Duty.uu_id == data.department_uu_id).data
created_duties = Duties.find_or_create(
company_id=token_dict.selected_company.company_id,

View File

@@ -4,7 +4,9 @@ from fastapi import status
from fastapi.responses import JSONResponse
from api_validations.validations_request import (
InsertCompanyDuty, PatchRecord, ListOptions
InsertCompanyDuty,
PatchRecord,
ListOptions,
)
from databases import Duty
@@ -23,7 +25,9 @@ class DutyListEventMethods(MethodToEvent):
@classmethod
def duty_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
list_options: ListOptions,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
records = Duty.filter_active(
*Duty.get_smart_query(list_options.query),
@@ -42,7 +46,9 @@ class DutyCreateEventMethods(MethodToEvent):
@classmethod
def duty_create(
cls, data: InsertCompanyDuty, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
data: InsertCompanyDuty,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
created_duty = Duty.find_or_create(**data.excluded_dump())
Duty.save()
@@ -64,7 +70,12 @@ class DutyUpdateEventMethods(MethodToEvent):
}
@classmethod
def duty_update(cls, company_uu_id: str, data, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]):
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), # ?
@@ -104,9 +115,15 @@ 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={

View File

@@ -27,7 +27,9 @@ class EmployeeListEventMethods(MethodToEvent):
@classmethod
def employee_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
list_options: ListOptions,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
Employees.filter_attr = list_options
records = Employees.filter_active(
@@ -48,7 +50,9 @@ class EmployeeCreateEventMethods(MethodToEvent):
@classmethod
def employee_create(
cls, data: InsertEmployees, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
data: InsertEmployees,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
person = People.find_one(uu_id=data.people_uu_id)
staff = Staff.find_one(uu_id=data.staff_uu_id)
@@ -124,7 +128,10 @@ class EmployeePatchEventMethods(MethodToEvent):
@classmethod
def employee_patch(
cls, employee_uu_id: str, data: PatchRecord, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
cls,
employee_uu_id: str,
data: PatchRecord,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
):
find_one_employee = Employees.find_one_or_abort(uu_id=employee_uu_id)
access_authorized_employee = Employees.select_action(