events updated
This commit is contained in:
@@ -61,18 +61,18 @@ class CompanyCreateEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def company_create(
|
||||
cls, data: InsertCompany, token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
cls,
|
||||
data: InsertCompany,
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
created_company = Companies.create_action(
|
||||
data=data, token=token_dict
|
||||
)
|
||||
created_company = Companies.create_action(data=data, token=token_dict)
|
||||
created_company.related_company = token_dict.selected_company.company_uu_id
|
||||
created_company.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Create Company record",
|
||||
"data": created_company.get_dict()
|
||||
"data": created_company.get_dict(),
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
@@ -86,26 +86,39 @@ 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)
|
||||
access_authorized_company = Companies.select_action(
|
||||
duty_id=getattr(token_dict, "duty_id", 5),
|
||||
filter_expr=[Companies.id == token_dict.get("")],
|
||||
def company_update(
|
||||
cls,
|
||||
company_uu_id: str,
|
||||
data: UpdateCompany, token_dict: EmployeeTokenObject
|
||||
):
|
||||
Companies.pre_query = Companies.select_action(
|
||||
duty_id_list=[
|
||||
token_dict.selected_company.bulk_duties_id,
|
||||
token_dict.selected_company.duty_id,
|
||||
],
|
||||
)
|
||||
if access_authorized_company.count:
|
||||
updated_company = find_one_company.data.update(**data.excluded_dump())
|
||||
Companies.save()
|
||||
find_one_company = Companies.filter_one(
|
||||
Companies.uu_id == company_uu_id,
|
||||
Companies.valid_record_args(Companies),
|
||||
).data
|
||||
if not find_one_company:
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Company record",
|
||||
"data": updated_company,
|
||||
"data": {}
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
status_code=200,
|
||||
)
|
||||
updated_company = find_one_company.update(**data.excluded_dump())
|
||||
Companies.save()
|
||||
return JSONResponse(
|
||||
content={"completed": True, "message": "Update Company record", "data": {}},
|
||||
status_code=status.HTTP_200_OK,
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Company record",
|
||||
"data": updated_company,
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
|
||||
|
||||
@@ -117,11 +130,15 @@ class CompanyPatchEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def company_patch(cls, company_uu_id: str, data: PatchRecord, token_dict):
|
||||
def company_patch(
|
||||
cls, company_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject
|
||||
):
|
||||
find_one_company = Companies.find_one_or_abort(uu_id=company_uu_id)
|
||||
access_authorized_company = Companies.select_action(
|
||||
duty_id=getattr(token_dict, "duty_id", 5),
|
||||
filter_expr=[Companies.id == find_one_company.id],
|
||||
duty_id_list=[
|
||||
token_dict.selected_company.bulk_duties_id,
|
||||
token_dict.selected_company.duty_id,
|
||||
],
|
||||
)
|
||||
if access_authorized_company.count:
|
||||
action = data.excluded_dump()
|
||||
@@ -152,7 +169,6 @@ class CompanyPatchEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
|
||||
|
||||
CompanyPatchEventMethod = CompanyListEventMethods(
|
||||
action=ActionsSchema(endpoint="/company/list")
|
||||
)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from typing import Optional, Union
|
||||
from typing import Optional
|
||||
from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
@@ -12,7 +12,7 @@ from api_validations.validations_request import (
|
||||
from databases import Departments
|
||||
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject
|
||||
from api_validations.core_response import AlchemyJsonResponse
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class DepartmentListEventMethods(MethodToEvent):
|
||||
def department_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
Departments.filter_attr = list_options
|
||||
records = Departments.filter_active(
|
||||
@@ -58,7 +58,9 @@ class DepartmentCreateEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def super_user_department_create(cls, data: DepartmentsPydantic, token_dict):
|
||||
def super_user_department_create(
|
||||
cls, data: DepartmentsPydantic, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
data_dict = data.excluded_dump()
|
||||
data_dict["company_id"] = token_dict.selected_company.company_id
|
||||
data_dict["company_uu_id"] = token_dict.selected_company.company_uu_id
|
||||
@@ -83,7 +85,7 @@ class DepartmentUpdateEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def department_update(
|
||||
cls, company_uu_id: str, data: DepartmentsPydantic, token_dict
|
||||
cls, company_uu_id: str, data: DepartmentsPydantic, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
find_one_company = Departments.filter_one(Departments.uu_id == company_uu_id)
|
||||
access_authorized_company = Departments.select_action(
|
||||
@@ -116,7 +118,9 @@ class DepartmentPatchEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def department_patch(cls, company_uu_id: str, data: PatchRecord, token_dict):
|
||||
def department_patch(
|
||||
cls, company_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject
|
||||
):
|
||||
find_one_company = Departments.find_one_or_abort(uu_id=company_uu_id)
|
||||
access_authorized_company = Departments.select_action(
|
||||
duty_id=getattr(token_dict, "duty_id", 5),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Union
|
||||
|
||||
from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
@@ -14,7 +12,7 @@ from api_validations.validations_request import (
|
||||
from databases import Departments, Duty, Duties
|
||||
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject
|
||||
|
||||
|
||||
class DutiesListEventMethods(MethodToEvent):
|
||||
@@ -28,7 +26,7 @@ class DutiesListEventMethods(MethodToEvent):
|
||||
def duties_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
Duties.filter_attr = list_options
|
||||
records = Duties.filter_all(
|
||||
@@ -53,7 +51,7 @@ class DutiesGetByUUIDEventMethods(MethodToEvent):
|
||||
def duties_get_by_uuid(
|
||||
cls,
|
||||
data: SelectDuties,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
|
||||
duty = Duty.filter_one(Duty.uu_id == data.duty_uu_id).data
|
||||
@@ -98,7 +96,7 @@ class DutiesCreateEventMethods(MethodToEvent):
|
||||
def duties_create(
|
||||
cls,
|
||||
data: InsertDuties,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
duty = Duty.filter_one(Duty.uu_id == data.duties_uu_id).data
|
||||
department = Departments.filter_one(Duty.uu_id == data.department_uu_id).data
|
||||
@@ -144,7 +142,12 @@ class DutiesUpdateEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def duties_update(cls, duties_uu_id: str, data: UpdateDuties, token_dict):
|
||||
def duties_update(
|
||||
cls,
|
||||
duties_uu_id: str,
|
||||
data: UpdateDuties,
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
find_one_duties = Duties.find_one_or_abort(uu_id=duties_uu_id)
|
||||
access_authorized_duties = Duties.select_action(
|
||||
duty_id=getattr(token_dict, "duty_id", 5),
|
||||
@@ -174,7 +177,9 @@ class DutiesPatchEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def duties_patch(cls, duties_uu_id: str, data: PatchRecord, token_dict):
|
||||
def duties_patch(
|
||||
cls, duties_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
find_one_duties = Duties.find_one_or_abort(uu_id=duties_uu_id)
|
||||
access_authorized_duties = Duties.select_action(
|
||||
duty_id=getattr(token_dict, "duty_id", 5),
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import Union
|
||||
|
||||
from fastapi import status
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
@@ -27,7 +25,7 @@ class DutyListEventMethods(MethodToEvent):
|
||||
def duty_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
records = Duty.filter_active(
|
||||
*Duty.get_smart_query(list_options.query),
|
||||
@@ -50,7 +48,7 @@ class DutyCreateEventMethods(MethodToEvent):
|
||||
def duty_create(
|
||||
cls,
|
||||
data: InsertCompanyDuty,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
created_duty = Duty.find_or_create(**data.excluded_dump())
|
||||
Duty.save()
|
||||
@@ -76,7 +74,7 @@ class DutyUpdateEventMethods(MethodToEvent):
|
||||
cls,
|
||||
company_uu_id: str,
|
||||
data,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
find_one_company = Duty.find_one_or_abort(uu_id=company_uu_id)
|
||||
access_authorized_company = Duty.select_action(
|
||||
@@ -109,7 +107,9 @@ class DutyPatchEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def duty_patch(cls, company_uu_id: str, data: PatchRecord, token_dict):
|
||||
def duty_patch(
|
||||
cls, company_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
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),
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
from datetime import datetime
|
||||
from typing import Union
|
||||
|
||||
from fastapi import status, HTTPException
|
||||
from fastapi.responses import JSONResponse
|
||||
|
||||
@@ -30,7 +27,7 @@ class EmployeeListEventMethods(MethodToEvent):
|
||||
def employee_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
Employees.filter_attr = list_options
|
||||
records = Employees.filter_active(
|
||||
@@ -55,7 +52,7 @@ class EmployeeCreateEventMethods(MethodToEvent):
|
||||
def employee_create(
|
||||
cls,
|
||||
data: InsertEmployees,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
person = People.filter_one(
|
||||
People.uu_id == data.people_uu_id,
|
||||
@@ -99,7 +96,9 @@ class EmployeeUpdateEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def employee_update(cls, employee_uu_id: str, data: PatchRecord, token_dict):
|
||||
def employee_update(
|
||||
cls, employee_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
find_one_employee = Employees.filter_one(
|
||||
Employees.uu_id == employee_uu_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
@@ -142,7 +141,7 @@ class EmployeePatchEventMethods(MethodToEvent):
|
||||
cls,
|
||||
employee_uu_id: str,
|
||||
data: PatchRecord,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
token_dict: EmployeeTokenObject,
|
||||
):
|
||||
find_one_employee = Employees.find_one_or_abort(uu_id=employee_uu_id)
|
||||
access_authorized_employee = Employees.select_action(
|
||||
@@ -186,7 +185,9 @@ class Employee2PeopleEmployEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def company_employee_employ(cls, data: BindEmployees2People, token_dict):
|
||||
def company_employee_employ(
|
||||
cls, data: BindEmployees2People, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
selected_staff = Staff.filter_one(
|
||||
Staff.uu_id == data.staff_uu_id,
|
||||
*Staff.valid_record_args(Staff),
|
||||
@@ -248,7 +249,9 @@ class Employee2PeopleFireEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def company_employee_fire(cls, data: BindEmployees2People, token_dict):
|
||||
def company_employee_fire(
|
||||
cls, data: BindEmployees2People, token_dict: EmployeeTokenObject,
|
||||
):
|
||||
selected_people = People.filter_one(
|
||||
People.uu_id == data.people_uu_id,
|
||||
*People.valid_record_args(People),
|
||||
|
||||
@@ -12,7 +12,7 @@ from api_validations.validations_request import (
|
||||
from databases import Staff, Duties
|
||||
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject
|
||||
from api_validations.core_response import AlchemyJsonResponse
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ class StaffListEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def staff_list(cls, list_options: ListOptions, token_dict):
|
||||
def staff_list(
|
||||
cls, list_options: ListOptions, token_dict: EmployeeTokenObject
|
||||
):
|
||||
Staff.filter_attr = list_options
|
||||
records = Staff.filter_active(
|
||||
*Staff.get_smart_query(smart_query=list_options.query),
|
||||
@@ -42,7 +44,9 @@ class StaffCreateEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def staff_create(cls, data: InsertStaff, token_dict: EmployeeTokenObject):
|
||||
def staff_create(
|
||||
cls, data: InsertStaff, token_dict: EmployeeTokenObject
|
||||
):
|
||||
data_dict = data.excluded_dump()
|
||||
duties = Duties.filter_one(
|
||||
Duties.uu_id == data.duties_uu_id,
|
||||
@@ -74,7 +78,9 @@ class StaffGetByUUIDEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def staff_get_by_uu_id(cls, data: SelectStaff, token_dict):
|
||||
def staff_get_by_uu_id(
|
||||
cls, data: SelectStaff, token_dict: EmployeeTokenObject
|
||||
):
|
||||
if data.duties_uu_id:
|
||||
duties_id = Duties.filter_one(
|
||||
Duties.uu_id == data.duties_uu_id, *Duties.valid_record_args(Duties)
|
||||
@@ -111,7 +117,9 @@ class StaffUpdateEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def staff_update(cls, staff_uu_id: str, data, token_dict):
|
||||
def staff_update(
|
||||
cls, staff_uu_id: str, data, token_dict: EmployeeTokenObject
|
||||
):
|
||||
return JSONResponse(
|
||||
content={"completed": True, "message": "Update Staff record", "data": {}},
|
||||
status_code=status.HTTP_200_OK,
|
||||
@@ -126,7 +134,9 @@ class StaffPatchEventMethods(MethodToEvent):
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def staff_patch(cls, staff_uu_id: str, data: PatchRecord, token_dict):
|
||||
def staff_patch(
|
||||
cls, staff_uu_id: str, data: PatchRecord, token_dict: EmployeeTokenObject
|
||||
):
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": False,
|
||||
|
||||
Reference in New Issue
Block a user