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

@@ -99,6 +99,7 @@ class AddressCreateEventMethods(MethodToEvent):
company_id=token_dict.selected_company.company_id,
is_confirmed=True,
)
Addresses.save()
return JSONResponse(
content={
"completed": True,
@@ -118,7 +119,7 @@ class AddressSearchEventMethods(MethodToEvent):
@classmethod
def search_address(cls, data: SearchAddress, token_dict):
import database_sql_models
import databases as database_sql_models
from time import perf_counter
st = perf_counter()
@@ -201,6 +202,7 @@ class AddressUpdateEventMethods(MethodToEvent):
del data_dict["post_code_uu_id"]
updated_address = address.update(**data_dict)
updated_address.save()
return JSONResponse(
content={
"completed": True,
@@ -221,8 +223,8 @@ class AddressPatchEventMethods(MethodToEvent):
@classmethod
def patch_address(cls, address_uu_id: str, data: InsertAddress, token_dict):
address = Addresses.find_one_or_abort(uu_id=address_uu_id)
post_code = RelationshipEmployee2PostCode.postcode.find_one(
member_id=address.post_code_id
post_code = RelationshipEmployee2PostCode.filter_one(
RelationshipEmployee2PostCode.member_id==address.post_code_id
)
if not post_code:
raise HTTPException(
@@ -273,6 +275,7 @@ class AddressPostCodeCreateEventMethods(MethodToEvent):
company_id=token_dict.selected_company.company_id,
is_confirmed=True,
)
AddressStreet.save()
return JSONResponse(
content={
"completed": True,
@@ -303,6 +306,7 @@ class AddressPostCodeUpdateEventMethods(MethodToEvent):
)
updated_post_code = post_code.update(**data.excluded_dump())
updated_post_code.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -44,11 +44,11 @@ from api_services import (
redis_cli,
send_email,
)
from api_validations.core_response import return_json_response_from_alchemy
from api_configs import ApiStatic, Auth
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_library.date_time_actions.date_functions import DateTimeLocal
from api_library.date_time_actions.date_functions import system_arrow, client_arrow
from api_validations.core_response import return_json_response_from_alchemy
class AuthenticationLoginEventMethods(MethodToEvent):
@@ -511,7 +511,7 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
found_user.last_remote_addr = getattr(
request, "remote_addr", None
) or request.headers.get("X-Forwarded-For", None)
found_user.last_seen = str(DateTimeLocal.now())
found_user.last_seen = str(system_arrow.now())
# UserLogger.log_error(
# str(
# dict(
@@ -593,7 +593,7 @@ class AuthenticationForgotPasswordEventMethods(MethodToEvent):
)
found_user.password_token = forgot_key
found_user.password_token_is_valid = str(DateTimeLocal.shift(days=1))
found_user.password_token_is_valid = str(system_arrow.shift(days=1))
found_user.save()
return JSONResponse(
@@ -620,6 +620,13 @@ class AuthenticationDownloadAvatarEventMethods(MethodToEvent):
found_user = Users.check_user_exits(
access_key=data.access_key, domain=data.domain
)
expired_str = str(system_arrow.now() - system_arrow.get(str(found_user.expiry_ends)))
expired_int = int(
client_arrow.get(
system_arrow.now() - system_arrow.get(str(found_user.expiry_ends))
).days
)
expiry_ends = system_arrow.get(str(found_user.expiry_ends))
return JSONResponse(
content={
"completed": True,
@@ -628,17 +635,9 @@ class AuthenticationDownloadAvatarEventMethods(MethodToEvent):
"last_seen": str(found_user.last_seen),
"avatar": found_user.avatar,
"remember_me": found_user.remember_me,
"expiry_ends": str(found_user.expiry_ends),
"expired_str": str(
DateTimeLocal.now()
- DateTimeLocal.get(str(found_user.expiry_ends))
),
"expired_int": int(
(
DateTimeLocal.now()
- DateTimeLocal.get(str(found_user.expiry_ends))
).days
),
"expiry_ends": client_arrow.get(expiry_ends),
"expired_str": client_arrow.get(expired_str),
"expired_int": expired_int,
},
},
status_code=status.HTTP_200_OK,

View File

@@ -5,14 +5,14 @@ from fastapi.responses import JSONResponse
from databases import (
Build,
# RelationshipEmployee2Build,
RelationshipEmployee2Build,
Addresses,
BuildParts,
BuildTypes,
ApiEnumDropdown,
)
from api_validations import (
from api_validations.validations_request import (
InsertBuild,
UpdateBuild,
PatchRecord,

View File

@@ -9,7 +9,7 @@ from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
from api_validations import (
from api_validations.validations_request import (
InsertBuildParts,
ListOptions,
)
@@ -58,6 +58,7 @@ class BuildingBuildPartsCreateEventMethods(MethodToEvent):
},
status_code=status.HTTP_406_NOT_ACCEPTABLE,
)
created_build.save()
return JSONResponse(
content={
"completed": True,
@@ -78,6 +79,7 @@ class BuildingBuildPartsUpdateEventMethods(MethodToEvent):
@classmethod
def building_build_parts_update(cls, data: InsertBuildParts, token_dict: dict):
if updated_build := BuildParts.update_action(data=data, token=token_dict):
updated_build.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -2,21 +2,24 @@ import typing
from fastapi import status, HTTPException
from api_events.events.events.events_bind_modules import ModulesBindOccupantEventMethods
from databases import (
BuildParts,
Build,
BuildLivingSpace,
OccupantTypes,
People,
)
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
from api_validations import (
from api_validations.validations_request import (
InsertBuildLivingSpace,
ListOptions,
)
from databases.sql_models.event.event import Modules
class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
@@ -86,24 +89,23 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
data: InsertBuildLivingSpace,
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
):
from service_app.application import DateTimeLocal
from database_sql_models import People
from api_library.date_time_actions.date_functions import system_arrow
from sqlalchemy.sql import select
data_dict = data.dump()
build_id_list_query = Build.select_action(
employee_id=token_dict.selected_company.employee_id
)
build_part = BuildParts.filter_active(
build_part = BuildParts.filter_one(
BuildParts.uu_id == data.build_parts_uu_id,
BuildParts.build_id.in_([build.id for build in build_id_list_query.all()]),
)
if not build_part.get(1):
if not build_part.data:
raise HTTPException(
status_code=status.HTTP_418_IM_A_TEAPOT,
detail=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
)
build_part = build_part.get(1)
build_part = build_part.data
life_person = People.find_one(uu_id=data.person_uu_id or "")
if not life_person:
@@ -137,26 +139,33 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
BuildLivingSpace.occupant_type == occupant_type.id,
BuildLivingSpace.active == True,
BuildLivingSpace.is_confirmed == True,
str(DateTimeLocal.now()) < BuildLivingSpace.expiry_ends,
str(DateTimeLocal.now()) >= BuildLivingSpace.expiry_starts,
str(system_arrow.now()) < BuildLivingSpace.expiry_ends,
str(system_arrow.now()) >= BuildLivingSpace.expiry_starts,
]
)
.order_by(BuildLivingSpace.expiry_starts.desc())
).first()
last_living_space = BuildLivingSpace.find_one(
id=living_space_id[0] if living_space_id else None
last_living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.id==living_space_id[0] if living_space_id else None
)
data_dict["expiry_starts"] = str(DateTimeLocal.now())
data_dict["expiry_starts"] = str(system_arrow.now())
created_living_space = BuildLivingSpace.create_action(
data=data_dict, token_dict=token_dict
)
if last_living_space:
if last_living_space.expiry_ends > DateTimeLocal.now():
last_living_space.expiry_ends = str(DateTimeLocal.shift(minutes=-10))
if last_living_space.expiry_ends > system_arrow.now():
last_living_space.expiry_ends = str(system_arrow.shift(minutes=-10))
last_living_space.save()
user_module = Modules.filter_one(Modules.module_code == "USR-PUB")
ModulesBindOccupantEventMethods.modules_bind_occupant_system(
build_living_space_id=created_living_space.id,
modules_id=user_module.id,
)
created_living_space.save()
return created_living_space
@@ -164,13 +173,12 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
event_type = "UPDATE"
__event_keys__ = {
"70b4666f-4ceb-46ec-b89e-24be8712f0e7": "building_build_parts_update"
"70b4666f-4ceb-46ec-b89e-24be8712f0e7": "building_live_space_update",
}
@classmethod
def building_build_parts_update(cls, build_uu_id: str, data, token_dict):
from service_app.application import DateTimeLocal
from database_sql_models import People
def building_live_space_update(cls, build_uu_id: str, data, token_dict):
from api_library.date_time_actions.date_functions import system_arrow
from sqlalchemy.sql import select
data_dict = data.dump()
@@ -200,11 +208,11 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
BuildLivingSpace.expiry_starts.desc()
)
living_space_id = BuildLivingSpace.session.execute(living_spaces).first()
last_living_space = BuildLivingSpace.find_one(
id=getattr(living_space_id[0], "id", None) if living_space_id else None
last_living_space = BuildLivingSpace.filter_one(
BuildLivingSpace.id==getattr(living_space_id[0], "id", None) if living_space_id else None
)
data_dict["expiry_starts"] = DateTimeLocal.now()
data_dict["expiry_starts"] = str(system_arrow.now())
data_dict["is_tenant_live"] = bool(data.is_tenant_live)
data_dict["build_parts_id"] = build_part.id
if data_dict["is_tenant_live"]:

View File

@@ -5,7 +5,7 @@ from fastapi.responses import JSONResponse
from databases import Companies
from api_validations import (
from api_validations.validations_request import (
InsertCompany,
UpdateCompany,
ListOptions,
@@ -63,6 +63,8 @@ class CompanyCreateEventMethods(MethodToEvent):
data=data, token=token_dict.companies_list
)
created_company.related_company = token_dict.get("company_uu_id")
created_company.flush()
created_company.save()
return JSONResponse(
content={
"completed": True,
@@ -91,14 +93,14 @@ class CompanyUpdateEventMethods(MethodToEvent):
@classmethod
def company_update(cls, company_uu_id: str, data: UpdateCompany, token_dict):
find_one_company = Companies.find_one_or_abort(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("")],
)
if access_authorized_company.count:
data_dict = data.excluded_dump()
updated_company = find_one_company.update(**data_dict)
updated_company = find_one_company.data.update(**data.excluded_dump())
Companies.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -1,8 +1,8 @@
from typing import Optional
from typing import Optional, Union
from fastapi import status
from fastapi.responses import JSONResponse
from validations import (
from api_validations.validations_request import (
DepartmentsPydantic,
PatchRecord,
ListOptions,
@@ -24,7 +24,9 @@ class DepartmentListEventMethods(MethodToEvent):
}
@classmethod
def department_list(cls, list_options: ListOptions, token_dict):
def department_list(
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),
@@ -57,22 +59,14 @@ class DepartmentCreateEventMethods(MethodToEvent):
data_dict["company_id"] = token_dict.selected_company.company_id
data_dict["company_uu_id"] = token_dict.selected_company.company_uu_id
created_department = Departments.find_or_create(**data_dict)
if created_department.is_found:
return JSONResponse(
content={
"completed": False,
"message": "Company record already exits here is the record",
"data": created_department.get_dict(),
},
status_code=status.HTTP_202_ACCEPTED,
)
Departments.save()
return JSONResponse(
content={
"completed": True,
"message": "Create Company record",
"completed": False,
"message": "Company record already exits here is the record",
"data": created_department.get_dict(),
},
status_code=status.HTTP_200_OK,
status_code=status.HTTP_202_ACCEPTED,
)
@@ -87,7 +81,7 @@ class DepartmentUpdateEventMethods(MethodToEvent):
def department_update(
cls, company_uu_id: str, data: DepartmentsPydantic, token_dict
):
find_one_company = Departments.find_one_or_abort(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("")],
@@ -95,6 +89,7 @@ class DepartmentUpdateEventMethods(MethodToEvent):
if access_authorized_company.count:
data_dict = data.excluded_dump()
updated_company = find_one_company.update(**data_dict)
Departments.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -1,8 +1,15 @@
from typing import Union
from fastapi import status
from fastapi.responses import JSONResponse
from validations import InsertDuties, UpdateDuties, SelectDuties
from validations.root_validates import PatchRecord, ListOptions
from api_validations.validations_request import (
InsertDuties,
UpdateDuties,
SelectDuties,
PatchRecord,
ListOptions,
)
from databases import Departments, Duty, Duties
@@ -19,9 +26,11 @@ class DutiesListEventMethods(MethodToEvent):
}
@classmethod
def duties_list(cls, list_options: ListOptions, token_dict):
def duties_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
Duties.filter_attr = list_options
records = Duties.filter_active(
records = Duties.filter_all(
*Duties.get_smart_query(smart_query=list_options.query),
Duties.company_id == token_dict.selected_company.company_id
)
@@ -40,9 +49,11 @@ class DutiesGetByUUIDEventMethods(MethodToEvent):
}
@classmethod
def duties_get_by_uuid(cls, data: SelectDuties, token_dict):
def duties_get_by_uuid(
cls, data: SelectDuties, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
duty = Duty.find_one(uu_id=data.duty_uu_id)
duty = Duty.filter_one(Duty.uu_id==data.duty_uu_id).data
if not duty:
return JSONResponse(
content={
@@ -81,9 +92,11 @@ class DutiesCreateEventMethods(MethodToEvent):
}
@classmethod
def duties_create(cls, data: InsertDuties, token_dict):
duty = Duty.find_one(uu_id=data.duties_uu_id)
department = Departments.find_one(uu_id=data.department_uu_id)
def duties_create(
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
created_duties = Duties.find_or_create(
company_id=token_dict.selected_company.company_id,
@@ -98,6 +111,7 @@ class DutiesCreateEventMethods(MethodToEvent):
created_duties.update(users_default_duty=created_duties.id)
if not created_duties:
Duty.save()
return JSONResponse(
content={
"completed": False,
@@ -134,6 +148,7 @@ class DutiesUpdateEventMethods(MethodToEvent):
if access_authorized_duties.count:
data_dict = data.excluded_dump()
updated_duties = find_one_duties.update(**data_dict)
Duties.save()
return {
"completed": True,
"message": "Update Duties record",

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={

View File

@@ -1,9 +1,10 @@
from datetime import datetime
from typing import Union
from fastapi import status, HTTPException
from fastapi.responses import JSONResponse
from validations import (
from api_validations.validations_request import (
InsertEmployees,
BindEmployees2People,
PatchRecord,
@@ -25,7 +26,9 @@ class EmployeeListEventMethods(MethodToEvent):
}
@classmethod
def employee_list(cls, list_options: ListOptions, token_dict):
def employee_list(
cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
Employees.filter_attr = list_options
records = Employees.filter_active(
*Employees.get_smart_query(smart_query=list_options.query),
@@ -44,7 +47,9 @@ class EmployeeCreateEventMethods(MethodToEvent):
}
@classmethod
def employee_create(cls, data: InsertEmployees, token_dict):
def employee_create(
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)
if not staff:
@@ -63,6 +68,7 @@ class EmployeeCreateEventMethods(MethodToEvent):
people_id=person.id if person else None,
people_uu_id=str(person.uu_id) if person else None,
)
Employees.save()
return JSONResponse(
content={
"completed": True if not created_employee.is_found else False,
@@ -90,6 +96,7 @@ class EmployeeUpdateEventMethods(MethodToEvent):
if access_authorized_employee.count:
data_dict = data.excluded_dump()
updated_employee = find_one_employee.update(**data_dict)
Employees.save()
return JSONResponse(
content={
"completed": True,
@@ -116,7 +123,9 @@ class EmployeePatchEventMethods(MethodToEvent):
}
@classmethod
def employee_patch(cls, employee_uu_id: str, data: PatchRecord, token_dict):
def employee_patch(
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(
employee_id=getattr(token_dict, "employee_id", 5),
@@ -133,7 +142,6 @@ class EmployeePatchEventMethods(MethodToEvent):
find_one_employee.deleted = bool(
action.get("delete", find_one_employee.deleted)
)
find_one_employee.save()
return JSONResponse(
content={
"completed": True,
@@ -197,7 +205,7 @@ class Employee2PeopleEmployEventMethods(MethodToEvent):
expiry_starts=data.expiry_starts,
**token_dict.update_creds,
)
Employees.save()
return JSONResponse(
content={
"completed": True,
@@ -257,6 +265,7 @@ class Employee2PeopleFireEventMethods(MethodToEvent):
is_notification_send=find_one_employee.is_notification_send,
cryp_uu_id=find_one_employee.cryp_uu_id,
)
Employees.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -2,7 +2,7 @@ from fastapi import status
from fastapi.responses import JSONResponse
from fastapi.exceptions import HTTPException
from validations import (
from api_validations.validations_request import (
InsertStaff,
SelectStaff,
PatchRecord,
@@ -48,10 +48,9 @@ class StaffCreateEventMethods(MethodToEvent):
status_code=status.HTTP_404_NOT_FOUND,
detail="Duties not found",
)
data_dict["duties_id"] = duties.id
created_duty = Staff.find_or_create(**data_dict)
Staff.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -10,7 +10,7 @@ from databases import (
OccupantTypes,
)
from validations import (
from api_validations.validations_request import (
InsertDecisionBook,
ListOptions,
)
@@ -117,6 +117,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
)
data_dict["expiry_starts"] = str(data_dict["expiry_starts"])
build_decision_book = BuildDecisionBook.find_or_create(**data_dict)
BuildDecisionBook.save()
return JSONResponse(
status_code=status.HTTP_200_OK,
content=dict(
@@ -157,6 +158,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
)
data_dict["expiry_starts"] = str(data_dict["expiry_starts"])
build_decision_book = BuildDecisionBook.find_or_create(**data_dict)
BuildDecisionBook.save()
return JSONResponse(
status_code=status.HTTP_200_OK,
content=dict(

View File

@@ -21,9 +21,9 @@ from databases import (
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
from api_library.date_time_actions.date_functions import DateTimeLocal
from api_library.date_time_actions.date_functions import system_arrow, client_arrow
from validations import (
from api_validations.validations_request import (
InsertBuildDecisionBookItems,
ListDecisionBook,
)
@@ -123,7 +123,7 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
for build_part_single in build_parts_list:
local_date = start_date
while local_date.is_between(start_date, end_date, "[]"):
local_date = DateTimeLocal.find_last_day_of_month(local_date)
local_date = system_arrow.find_last_day_of_month(local_date)
payment_amount = unit_price
if not unit_price_is_fixed:
unit_amount = str(build_part_single.due_part_key).replace(" ", "")
@@ -176,9 +176,9 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
)
payment_types = ApiEnumDropdown.get_debit_search(search_debit="DT-D")
if data_info_type.key == "BDT-D":
local_date = DateTimeLocal.get(DateTimeLocal.get(decision_book.expiry_starts).date())
end_date = DateTimeLocal.get(DateTimeLocal.get(decision_book.expiry_ends).date())
return cls.iterate_over_build_parts(
local_date = system_arrow.get(system_arrow.get(decision_book.expiry_starts).date())
end_date = system_arrow.get(system_arrow.get(decision_book.expiry_ends).date())
cls.iterate_over_build_parts(
build_parts_list=build_parts_list.data,
payment_types=payment_types,
local_date=local_date,
@@ -188,10 +188,12 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
unit_price_is_fixed=unit_price_is_fixed,
book_payment_dict=book_payment_dict,
)
BuildDecisionBookProjects.save()
return
elif data_info_type.key == "BDT-A":
local_date = DateTimeLocal.get(DateTimeLocal.get(debit_start_date).date())
end_date = DateTimeLocal.get(DateTimeLocal.get(debit_end_date).date())
return cls.iterate_over_build_parts(
local_date = system_arrow.get(system_arrow.get(debit_start_date).date())
end_date = system_arrow.get(system_arrow.get(debit_end_date).date())
cls.iterate_over_build_parts(
build_parts_list=build_parts_list.data,
payment_types=payment_types,
local_date=local_date,
@@ -201,11 +203,13 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
unit_price_is_fixed=unit_price_is_fixed,
book_payment_dict=book_payment_dict,
)
BuildDecisionBookProjects.save()
return
elif data_info_type.key == "BDT-R" or data_info_type.key == "BDT-L":
local_date = DateTimeLocal.get(DateTimeLocal.get(debit_start_date).date())
end_date = DateTimeLocal.get(DateTimeLocal.get(debit_end_date).date())
decision_date = DateTimeLocal.get(decision_book.expiry_starts).date()
meeting_date = DateTimeLocal.get(decision_book.meeting_date).date()
local_date = system_arrow.get(system_arrow.get(debit_start_date).date())
end_date = system_arrow.get(system_arrow.get(debit_end_date).date())
decision_date = system_arrow.get(decision_book.expiry_starts).date()
meeting_date = system_arrow.get(decision_book.meeting_date).date()
already_book_projects = BuildDecisionBookProjects.filter_all(
BuildDecisionBookProjects.build_decision_book_id==decision_book.id,
@@ -242,22 +246,23 @@ class DecisionBookDecisionBookItemsCreateEventMethods(MethodToEvent):
project_response_living_space_uu_id=str(manager_living_space.uu_id),
)
book_project_created = BuildDecisionBookProjects.find_or_create(**book_project_dict)
if not book_project_created.is_found:
decision_book_item.update(
item_comment=f"{book_project_created.project_no}_{book_project_created.project_name} "
f"is assigned to {occupant_man.occupant_description}"
)
project_lead = ApiEnumDropdown.find_one(
key="PTT-LDR", enum_class="ProjectTeamTypes"
)
project_person = BuildDecisionBookProjectPerson.find_or_create(
build_decision_book_project_id=book_project_created.id,
build_decision_book_project_uu_id=str(book_project_created.uu_id),
living_space_id=manager_living_space.id,
living_space_uu_id=str(manager_living_space.uu_id),
project_team_type_id=project_lead.id,
project_team_type_uu_id=str(project_lead.uu_id),
)
decision_book_item.update(
item_comment=f"{book_project_created.project_no}_{book_project_created.project_name} "
f"is assigned to {occupant_man.occupant_description}"
)
project_lead = ApiEnumDropdown.find_one(
key="PTT-LDR", enum_class="ProjectTeamTypes"
)
project_person = BuildDecisionBookProjectPerson.find_or_create(
build_decision_book_project_id=book_project_created.id,
build_decision_book_project_uu_id=str(book_project_created.uu_id),
living_space_id=manager_living_space.id,
living_space_uu_id=str(manager_living_space.uu_id),
project_team_type_id=project_lead.id,
project_team_type_uu_id=str(project_lead.uu_id),
)
BuildDecisionBookProjects.save()
return
elif data_info_type.key == "BDT-SF":
raise HTTPException(

View File

@@ -15,7 +15,7 @@ from databases import (
OccupantTypes,
)
from api_validations import (
from api_validations.validations_request import (
ListOptions,
RemoveDecisionBookPerson,
DecisionBookDecisionBookInvitationsAttend,
@@ -126,6 +126,7 @@ class DecisionBookPersonAddEventMethods(MethodToEvent):
occupant_type=assign_occupant_type.id,
occupant_type_uu_id=str(assign_occupant_type.uu_id),
)
BuildDecisionBookPerson.save()
return JSONResponse(
status_code=status.HTTP_200_OK,
content={
@@ -200,6 +201,7 @@ class DecisionBookPersonAttendEventMethods(MethodToEvent):
invitation_person.update(
is_attending=bool(data.is_attend), vicarious_person_id=None
)
BuildDecisionBookInvitations.save()
return JSONResponse(
status_code=status.HTTP_200_OK,
content={
@@ -336,6 +338,7 @@ class DecisionBookPersonAssignOccupantEventMethods(MethodToEvent):
occupant_type=assign_occupant_type,
build_living_space_id=selected_living_space.id,
)
BuildDecisionBookPersonOccupants.save()
return JSONResponse(
status_code=status.HTTP_200_OK,
content={

View File

@@ -16,14 +16,14 @@ from databases import (
ApiEnumDropdown,
)
from api_validations import (
from api_validations.validations_request import (
DecisionBookDecisionBookInvitationsUpdate,
DecisionBookDecisionBookInvitations,
)
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
from api_library.date_time_actions.date_functions import DateTimeLocal
from api_library.date_time_actions.date_functions import system_arrow
class BuildDecisionBookInvitationsListEventMethods(MethodToEvent):
@@ -95,8 +95,8 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
# Check planned decision book date is valid
if (
not DateTimeLocal.get(data.planned_date).date()
>= DateTimeLocal.shift(days=1).date()
not system_arrow.get(data.planned_date).date()
>= system_arrow.shift(days=1).date()
):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
@@ -115,9 +115,9 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
message=data.message,
planned_date=data.planned_date,
planned_date_expires=str(
DateTimeLocal.get(data.planned_date).shift(days=15).date()
system_arrow.get(data.planned_date).shift(days=15).date()
),
expiry_ends=str(DateTimeLocal.get(data.planned_date).shift(days=15).date()),
expiry_ends=str(system_arrow.get(data.planned_date).shift(days=15).date()),
is_confirmed=True,
)
if book_invitation.is_found:
@@ -172,7 +172,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
build_decision_book_uu_id=str(decision_book.uu_id),
invite_id=book_invitation.id,
invite_uu_id=str(book_invitation.uu_id),
send_date=str(DateTimeLocal.now().date()),
send_date=str(system_arrow.now().date()),
expiry_starts=decision_book.expiry_starts,
expiry_ends=decision_book.expiry_ends,
is_confirmed=True,
@@ -243,6 +243,7 @@ class BuildDecisionBookInvitationsCreateEventMethods(MethodToEvent):
):
book_person_manager.add_occupant_type(occupant_type=manager_occupant_type)
print(f"Manager Token : {book_person_manager.token}")
BuildDecisionBookPerson.save()
return JSONResponse(
status_code=status.HTTP_200_OK,
content={

View File

@@ -1,3 +1,5 @@
from typing import Union
from fastapi import status
from fastapi.responses import JSONResponse
from fastapi.exceptions import HTTPException
@@ -8,9 +10,9 @@ from databases import (
Build,
Events,
Event2Occupant,
OccupantTypes,
OccupantTypes,
)
from api_validations import RegisterEvents2Occupant
from api_validations.validations_request import RegisterEvents2Occupant
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
@@ -24,7 +26,7 @@ class EventBindOccupantEventMethods(MethodToEvent):
@classmethod
def bind_events_occupant_super_user(
cls, data: RegisterEvents2Occupant, token_dict: EmployeeTokenObject
cls, data: RegisterEvents2Occupant, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
if not str(token_dict.user_type) == "1":
@@ -108,6 +110,7 @@ class EventBindOccupantEventMethods(MethodToEvent):
events_added.append(event)
if events_added:
Events.save()
return JSONResponse(
content={
"completed": True,
@@ -134,7 +137,9 @@ class EventBindEmployeeEventMethods(MethodToEvent):
}
@classmethod
def bind_events_employee(cls, data: RegisterEvents2Occupant, token_dict):
def bind_events_employee(
cls, data: RegisterEvents2Occupant, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
return token_dict.available_event(data=data, token_dict=token_dict)

View File

@@ -0,0 +1,74 @@
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 return_json_response_from_alchemy
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(Modules.id==build_living_space_id).data
modules = Modules.filter_one(Modules.id==modules_id).data
service_build_dict = dict(build_living_space_id=living_space.id)
service_build_dict["expires_at"] = str(system_arrow.get(living_space.expiry_ends))
if not expires_at:
service_build_dict["expires_at"] = str(system_arrow.get(expires_at))
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")
)

View File

@@ -15,7 +15,7 @@ from databases import (
Event2Employee,
Event2Occupant,
)
from api_validations import RegisterServices2Occupant, RegisterServices2Employee
from api_validations.validations_request import RegisterServices2Occupant, RegisterServices2Employee
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
@@ -33,21 +33,9 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
):
from sqlalchemy.dialects.postgresql import insert
living_space = BuildLivingSpace.find_or_abort(
id=build_living_space_id,
)
service = Services.find_or_abort(
id=service_id,
)
default_module = Modules.find_one(module_code="USR-PUB")
add_default_service = Services.find_one(module_id=default_module.id)
service_events = Service2Events.filter_all(
Service2Events.service_id == service.id,
)
default_service_events = Service2Events.filter_all(
Service2Events.service_id == add_default_service.id,
)
add_events_list = service_events.data + default_service_events.data
living_space = BuildLivingSpace.filter_one(BuildLivingSpace.id==build_living_space_id)
service = Services.filter_one(Services.id==service_id)
add_events_list = Service2Events.filter_all(Service2Events.service_id == service.id).data
if not add_events_list:
raise Exception(
"Service has no events registered. Please contact with your manager"
@@ -74,8 +62,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
)
count_row = session_execute.rowcount
print(f"{count_row} events are added to occupant {str(living_space.uu_id)}")
Services.session.commit()
Services.session.flush()
Services.save()
@classmethod
def bind_services_occupant(
@@ -178,8 +165,7 @@ class ServiceBindOccupantEventMethods(MethodToEvent):
)
count_row = session_execute.rowcount
print(f"{count_row} events are added to employee {str(living_space.uu_id)}")
Services.session.commit()
Services.session.flush()
Services.save()
class ServiceBindEmployeeEventMethods(MethodToEvent):
@@ -233,8 +219,7 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
)
count_row = session_execute.rowcount
print(f"{count_row} events are added to employee {employee.uu_id}")
Services.session.commit()
Services.session.flush()
Services.save()
@classmethod
def bind_services_employee_super_user(
@@ -308,9 +293,8 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
)
)
count_row = session_execute.rowcount
Services.session.commit()
Services.session.flush()
if not count_row:
Services.save()
return JSONResponse(
content={
"completed": False,

View File

@@ -1,3 +1,5 @@
from typing import Union
from fastapi.exceptions import HTTPException
from databases import (
@@ -9,7 +11,7 @@ from databases import (
Event2Employee,
BuildLivingSpace,
)
from api_validations import (
from api_validations.validations_request import (
RegisterEvents2Employee,
RegisterEvents2Occupant,
CreateEvents,
@@ -29,7 +31,7 @@ class EventsListEventMethods(MethodToEvent):
}
@classmethod
def events_list(cls, list_options: ListOptions, token_dict):
def events_list(cls, list_options: ListOptions, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]):
records = Events.filter_active(
*Events.get_smart_query(list_options.query),
)
@@ -56,6 +58,7 @@ class EventsCreateEventMethods(MethodToEvent):
active=True,
deleted=False,
)
Events.save()
return {
"status": "success",
"message": "Event created successfully.",
@@ -85,6 +88,7 @@ class EventsUpdateEventMethods(MethodToEvent):
event_date=data.event_date,
event_location=data.event_location,
)
Events.save()
return {
"status": "success",
"message": "Event updated successfully.",
@@ -155,6 +159,7 @@ class EventsBindEventToOccupantMethods(MethodToEvent):
employee = Event2Employee.find_or_create(
**token_dict.user_creds, employee_id=employee.id, event_id=event.id
)
Events.save()
return {
"status": "success",
"message": "Events registered successfully.",
@@ -191,6 +196,7 @@ class EventsBindEventToEmployeeMethods(MethodToEvent):
build_living_space_id=occupant.id,
event_id=event.id,
)
Events.save()
return {
"status": "success",
"message": "Events registered successfully.",

View File

@@ -1,85 +0,0 @@
from fastapi import status
from fastapi.responses import JSONResponse
from api_validations import DepartmentsPydantic, ListOptions
from databases import Events
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
class ModelEntitiesEvents(MethodToEvent):
@classmethod
def model_entities_list(cls, list_options: ListOptions, token_dict):
Events.filter_attr = list_options
records = Events.filter_active(
*Events.get_smart_query(smart_query=list_options.query),
Events.company_id == token_dict.selected_company.company_id
)
return return_json_response_from_alchemy(
response=records, pagination=list_options
)
@classmethod
def model_entities_create(cls, data: DepartmentsPydantic, token_dict):
created_events = Events.create_action(data=data, token=token_dict)
if created_events.is_found:
return JSONResponse(
content={
"completed": False,
"message": "Events record already exits here is the record",
"data": created_events.get_dict(),
},
status_code=status.HTTP_202_ACCEPTED,
)
return JSONResponse(
content={
"completed": True,
"message": "Create Events record",
"data": created_events.get_dict(),
},
status_code=status.HTTP_200_OK,
)
@classmethod
def model_entities_update(
cls, company_uu_id: str, data: DepartmentsPydantic, token_dict
):
find_one_events = Events.find_one_or_abort(uu_id=company_uu_id)
access_authorized_events = Events.select_action(
duty_id=getattr(token_dict, "duty_id", 5),
filter_expr=[Events.id == token_dict.get("")],
action="update",
data=data,
)
return JSONResponse(
content={
"completed": True,
"message": "Update Events record",
"data": access_authorized_events.get_dict(),
},
status_code=status.HTTP_200_OK,
)
@classmethod
def model_entities_patch(
cls, company_uu_id: str, data: DepartmentsPydantic, token_dict
):
find_one_events = Events.find_one_or_abort(uu_id=company_uu_id)
access_authorized_events = Events.select_action(
duty_id=getattr(token_dict, "duty_id", 5),
filter_expr=[Events.id == token_dict.get("")],
action="patch",
data=data,
)
return JSONResponse(
content={
"completed": True,
"message": "Patch Events record",
"data": access_authorized_events.get_dict(),
},
status_code=status.HTTP_200_OK,
)

View File

@@ -1,4 +1,4 @@
from validations import DepartmentsPydantic, PatchRecord, ListOptions
from api_validations.validations_request import DepartmentsPydantic, PatchRecord, ListOptions
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject

View File

@@ -1,4 +1,4 @@
from validations import DepartmentsPydantic, PatchRecord
from api_validations.validations_request import DepartmentsPydantic, PatchRecord
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject

View File

@@ -1,4 +1,4 @@
from validations import DepartmentsPydantic, PatchRecord, ListOptions
from api_validations.validations_request import DepartmentsPydantic, PatchRecord, ListOptions
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject

View File

@@ -1,3 +1,5 @@
from typing import Union
from fastapi import status
from fastapi.responses import JSONResponse
@@ -7,7 +9,7 @@ from databases import (
Companies,
)
from validations import InsertPerson, UpdateUsers
from api_validations.validations_request import InsertPerson, UpdateUsers
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
@@ -26,8 +28,6 @@ class PeopleListEventMethods(MethodToEvent):
@classmethod
def super_users_people_list(cls, list_options, token_dict):
records = People.filter_active(
*People.get_smart_query(smart_query=list_options.query)
)
@@ -58,9 +58,11 @@ class PeopleCreateEventMethods(MethodToEvent):
}
@classmethod
def people_create(cls, data: InsertPerson, token_dict: dict):
def people_create(
cls, data: InsertPerson, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
created_user = People.create_action(data=data, token=token_dict)
People.save()
return JSONResponse(
content={
"completed": True,
@@ -79,8 +81,9 @@ class PeopleUpdateEventMethods(MethodToEvent):
}
@classmethod
def people_update(cls, data: UpdateUsers, user_uu_id: str, token_dict: dict):
def people_update(
cls, data: UpdateUsers, user_uu_id: str, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
):
find_one_user = Users.find_one_or_abort(uu_id=user_uu_id)
access_authorized_company = Companies.select_action(
duty_id=getattr(token_dict, "duty_id", 5),
@@ -89,6 +92,7 @@ class PeopleUpdateEventMethods(MethodToEvent):
if access_authorized_company.count:
data_dict = data.excluded_dump()
updated_user = find_one_user.update(**data_dict)
Users.save()
return JSONResponse(
content={
"completed": True,

View File

@@ -3,15 +3,20 @@ import typing
from fastapi import status
from fastapi.responses import JSONResponse
from databases import MongoQueryIdentity, Users, Companies, People
from databases.no_sql_models.validations import DomainViaUser
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
from api_validations.core_response import return_json_response_from_alchemy
from validations import InsertUsers, UpdateUsers, PatchRecord, ListOptions
from api_validations.validations_request import (
InsertUsers,
UpdateUsers,
PatchRecord,
ListOptions, RegisterServices2Occupant,
)
class UserListEventMethods(MethodToEvent):
@@ -55,7 +60,9 @@ class UserCreateEventMethods(MethodToEvent):
}
@classmethod
def user_create(cls, data: InsertUsers, token_dict):
def user_create(
cls, data: InsertUsers, token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject]
):
created_user = Users.create_action(create_user=data)
created_user.related_company = token_dict.selected_company.company_uu_id
domain_via_user = DomainViaUser(
@@ -66,7 +73,6 @@ class UserCreateEventMethods(MethodToEvent):
company_uuid=created_user.related_company,
)
mongo_query_identity.create_domain_via_user(payload=domain_via_user)
return JSONResponse(
content={
"completed": True,
@@ -92,7 +98,9 @@ class UserUpdateEventMethods(MethodToEvent):
}
@classmethod
def user_update(cls, data: UpdateUsers, user_uu_id: str, token_dict):
def user_update(
cls, data: UpdateUsers, user_uu_id: str, token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject]
):
find_one_user = Users.find_one_or_abort(uu_id=user_uu_id)
access_authorized_company = Companies.select_action(
duty_id=getattr(token_dict, "duty_id", 5),
@@ -101,6 +109,7 @@ class UserUpdateEventMethods(MethodToEvent):
if access_authorized_company.count:
data_dict = data.excluded_dump()
updated_user = find_one_user.update(**data_dict)
Users.save()
return JSONResponse(
content={
"completed": True,