migrator completed
This commit is contained in:
@@ -56,6 +56,9 @@ from api_events.events.building.building_build_sites import (
|
||||
BuildSitesCreateEventMethod,
|
||||
BuildSitesUpdateEventMethod,
|
||||
)
|
||||
from api_events.events.building.building_build_types import (
|
||||
BuildTypesListEventMethod,
|
||||
)
|
||||
from api_events.events.company.company_company import (
|
||||
CompanyListEventMethod,
|
||||
CompanyCreateEventMethod,
|
||||
@@ -182,6 +185,7 @@ __all__ = [
|
||||
"BuildSitesListEventMethod",
|
||||
"BuildSitesCreateEventMethod",
|
||||
"BuildSitesUpdateEventMethod",
|
||||
"BuildTypesListEventMethod",
|
||||
"DecisionBookListEventMethod",
|
||||
"DecisionBookCreateEventMethod",
|
||||
"DecisionBookUpdateEventMethod",
|
||||
|
||||
@@ -13,7 +13,9 @@ from databases import (
|
||||
from api_validations.validations_request import (
|
||||
ListOptions,
|
||||
InsertAddress,
|
||||
UpdateAddress,
|
||||
InsertPostCode,
|
||||
UpdatePostCode,
|
||||
SearchAddress,
|
||||
)
|
||||
from api_validations.core_response import AlchemyJsonResponse
|
||||
@@ -117,16 +119,19 @@ class AddressCreateEventMethods(MethodToEvent):
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
data_dict["street_id"] = post_code.street_id
|
||||
data_dict["street_uu_id"] = str(post_code.street_uu_id)
|
||||
del data_dict["post_code_uu_id"]
|
||||
data_dict["is_confirmed"] = True
|
||||
address = Addresses.find_or_create(**data_dict)
|
||||
RelationshipEmployee2PostCode.find_or_create(
|
||||
relation_employee = RelationshipEmployee2PostCode.find_or_create(
|
||||
employee_id=token_dict.selected_company.employee_id,
|
||||
member_id=post_code.id,
|
||||
company_id=token_dict.selected_company.company_id,
|
||||
is_confirmed=True,
|
||||
)
|
||||
Addresses.save()
|
||||
address.save()
|
||||
address.update(is_confirmed=True)
|
||||
address.save()
|
||||
relation_employee.update(is_confirmed=True)
|
||||
relation_employee.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
@@ -220,39 +225,36 @@ class AddressUpdateEventMethods(MethodToEvent):
|
||||
def update_address(
|
||||
cls,
|
||||
address_uu_id: str,
|
||||
data: InsertAddress,
|
||||
data: UpdateAddress,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
address = Addresses.filter_one(
|
||||
Addresses.uu_id == address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
)
|
||||
post_code = RelationshipEmployee2PostCode.filter_one(
|
||||
RelationshipEmployee2PostCode.member_id == address.post_code_id,
|
||||
*RelationshipEmployee2PostCode.valid_record_args(
|
||||
RelationshipEmployee2PostCode
|
||||
),
|
||||
).data
|
||||
if not post_code:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Post code not found. User can not update address without post code.",
|
||||
)
|
||||
if isinstance(token_dict, EmployeeTokenObject):
|
||||
address = Addresses.filter_one(
|
||||
Addresses.uu_id == address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).data
|
||||
if not address:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"Address not found. User can not update with given address uuid : {address_uu_id}",
|
||||
)
|
||||
|
||||
data_dict = data.excluded_dump()
|
||||
data_dict["post_code_id"] = post_code.id
|
||||
del data_dict["post_code_uu_id"]
|
||||
data_dict["is_confirmed"] = True
|
||||
updated_address = address.update(**data_dict)
|
||||
updated_address.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Address record",
|
||||
"data": updated_address.get_dict(),
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
data_dict = data.excluded_dump()
|
||||
updated_address = address.update(**data_dict)
|
||||
updated_address.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Address record",
|
||||
"data": updated_address.get_dict(),
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Occupant can not update address.",
|
||||
)
|
||||
|
||||
|
||||
class AddressPatchEventMethods(MethodToEvent):
|
||||
@@ -325,16 +327,19 @@ class AddressPostCodeCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
data_dump["street_id"] = street.id
|
||||
data_dump["postcode"] = data.post_code
|
||||
del data_dump["street_uu_id"], data_dump["post_code"]
|
||||
del data_dump["post_code"]
|
||||
|
||||
post_code = AddressPostcode.find_or_create(**data_dump)
|
||||
AddressPostcode.__many__table__.find_or_create(
|
||||
relation_table = AddressPostcode.__many__table__.find_or_create(
|
||||
member_id=post_code.id,
|
||||
employee_id=token_dict.selected_company.employee_id,
|
||||
company_id=token_dict.selected_company.company_id,
|
||||
is_confirmed=True,
|
||||
)
|
||||
AddressStreet.save()
|
||||
post_code.save()
|
||||
post_code.update(is_confirmed=True)
|
||||
post_code.save()
|
||||
relation_table.update(is_confirmed=True)
|
||||
relation_table.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
@@ -356,30 +361,46 @@ class AddressPostCodeUpdateEventMethods(MethodToEvent):
|
||||
def update_post_code_address(
|
||||
cls,
|
||||
post_code_uu_id: str,
|
||||
data: InsertPostCode,
|
||||
data: UpdatePostCode,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
post_code = AddressPostcode.filter_one(
|
||||
AddressPostcode.uu_id == post_code_uu_id
|
||||
).data
|
||||
street = AddressStreet.filter_one(
|
||||
AddressPostcode.uu_id == data.street_uu_id
|
||||
).data
|
||||
if not street:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Street not found. User can not update post code without street.",
|
||||
if isinstance(token_dict, EmployeeTokenObject):
|
||||
AddressPostcode.pre_query = AddressPostcode.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id,
|
||||
)
|
||||
post_code = AddressPostcode.filter_one(
|
||||
AddressPostcode.uu_id == post_code_uu_id,
|
||||
*AddressPostcode.valid_record_args(AddressPostcode),
|
||||
).data
|
||||
if not post_code:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail="Street not found. User can not update post code without street.",
|
||||
)
|
||||
|
||||
updated_post_code = post_code.update(**data.excluded_dump())
|
||||
updated_post_code.save()
|
||||
data_dict = data.excluded_dump()
|
||||
updated_post_code = post_code.update(**data_dict)
|
||||
updated_post_code.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Post Code record",
|
||||
"data": updated_post_code.get_dict(),
|
||||
},
|
||||
status_code=200,
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="Occupant can not update post code.",
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Post Code record",
|
||||
"data": updated_post_code.get_dict(),
|
||||
"data": {},
|
||||
},
|
||||
status_code=200,
|
||||
status_code=404,
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ class AuthenticationLoginEventMethods(MethodToEvent):
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="This User has no active role registered. Please contact your administrator.",
|
||||
)
|
||||
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
|
||||
@@ -107,11 +107,20 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||
part_direction_uu_id=str(api_enum.uu_id),
|
||||
part_code="MAN-ROOM",
|
||||
human_livable=False,
|
||||
is_confirmed=True,
|
||||
)
|
||||
man_build_part = BuildParts.find_or_create(**build_parts)
|
||||
created_build.save()
|
||||
created_build.update(management_room_id=man_build_part.id)
|
||||
BuildParts.save()
|
||||
created_build.save()
|
||||
man_build_part.update(is_confirmed=True)
|
||||
man_build_part.save()
|
||||
# created_build_relation = RelationshipEmployee2Build.find_or_create(
|
||||
# company_id=token_dict.selected_company.company_id,
|
||||
# member_id=created_build.id,
|
||||
# employee_id=token_dict.selected_company.employee_id,
|
||||
# )
|
||||
# created_build_relation.update(is_confirmed=True)
|
||||
# created_build_relation.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
@@ -147,12 +156,13 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
created_build = Build.create_action(data=data, token=token_dict)
|
||||
RelationshipEmployee2Build.find_or_create(
|
||||
|
||||
created_build_relation = RelationshipEmployee2Build.find_or_create(
|
||||
company_id=token_dict.selected_company.company_id,
|
||||
member_id=created_build.id,
|
||||
employee_id=token_dict.selected_company.employee_id,
|
||||
is_confirmed=True,
|
||||
)
|
||||
created_build.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
@@ -207,7 +217,10 @@ class BuildPatchEventMethods(MethodToEvent):
|
||||
|
||||
@classmethod
|
||||
def build_patch(cls, build_uu_id: str, data: PatchRecord, token_dict):
|
||||
find_one_build = Build.find_one_or_abort(uu_id=build_uu_id)
|
||||
find_one_build = Build.filter_one(
|
||||
Build.uu_id==build_uu_id,
|
||||
*Build.valid_record_args(Build)
|
||||
)
|
||||
access_authorized_build = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id,
|
||||
filter_expr=[Build.id == find_one_build.id],
|
||||
|
||||
@@ -68,6 +68,8 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||
data: InsertBuildArea,
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
data_dict = data.excluded_dump()
|
||||
selected_build = None
|
||||
if isinstance(token_dict, OccupantTokenObject):
|
||||
if not token_dict.selected_occupant.build_uuid == data.build_uu_id:
|
||||
BuildArea.raise_http_exception(
|
||||
@@ -78,6 +80,7 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||
"build_uu_id": data.build_uu_id,
|
||||
},
|
||||
)
|
||||
selected_build = Build.filter_by_one(system=True, uu_id=data.build_uu_id).data
|
||||
elif isinstance(token_dict, EmployeeTokenObject):
|
||||
build_ids = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id
|
||||
@@ -91,7 +94,10 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||
"build_uu_id": data.build_uu_id,
|
||||
},
|
||||
)
|
||||
data_dict = data.excluded_dump()
|
||||
selected_build = Build.filter_by_one(system=True, uu_id=data.build_uu_id).data
|
||||
|
||||
data_dict["build_id"] = selected_build.id
|
||||
data_dict["build_uu_id"] = str(selected_build.uu_id)
|
||||
created_build_part = BuildArea.find_or_create(**data_dict)
|
||||
created_build_part.save()
|
||||
created_build_part.update(is_confirmed=True)
|
||||
@@ -99,7 +105,7 @@ class BuildAreaCreateEventMethods(MethodToEvent):
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Created Build Area",
|
||||
result=created_build_part,
|
||||
result=created_build_part.get_dict(),
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,49 @@
|
||||
from typing import Union
|
||||
|
||||
from api_events.events.abstract_class import MethodToEvent, ActionsSchema
|
||||
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_validations.core_response import AlchemyJsonResponse
|
||||
from api_validations.validations_request import (
|
||||
ListOptions,
|
||||
)
|
||||
from databases.sql_models.building.build import BuildTypes
|
||||
|
||||
|
||||
class BuildingBuildTypesEvents(MethodToEvent): ...
|
||||
class BuildTypesListEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "SELECT"
|
||||
__event_keys__ = {
|
||||
"5344d03c-fc47-43ec-8c44-6c2acd7e5d9f": "build_types_list",
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def build_types_list(
|
||||
cls,
|
||||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
):
|
||||
from fastapi.exceptions import HTTPException
|
||||
if isinstance(token_dict, EmployeeTokenObject):
|
||||
BuildTypes.filter_attr = list_options
|
||||
results = BuildTypes.filter_all(
|
||||
*BuildTypes.valid_record_args(BuildTypes)
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
result=results,
|
||||
message="Build Types are listed successfully",
|
||||
)
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="You are not authorized to access this endpoint"
|
||||
)
|
||||
else:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail="You are not authorized to access this endpoint"
|
||||
)
|
||||
|
||||
BuildTypesListEventMethod = BuildTypesListEventMethods(
|
||||
action=ActionsSchema(endpoint="/building/types/list")
|
||||
)
|
||||
@@ -131,7 +131,10 @@ class CompanyPatchEventMethods(MethodToEvent):
|
||||
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)
|
||||
find_one_company = Companies.filter_one(
|
||||
Companies.uu_id==company_uu_id,
|
||||
*Companies.valid_record_args(Companies)
|
||||
).data
|
||||
access_authorized_company = Companies.select_action(
|
||||
duty_id_list=[
|
||||
token_dict.selected_company.bulk_duties_id,
|
||||
|
||||
Reference in New Issue
Block a user