alcehmy and event functions updated
This commit is contained in:
@@ -39,16 +39,18 @@ class BuildListEventMethods(MethodToEvent):
|
||||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
if isinstance(token_dict, OccupantTokenObject):
|
||||
Build.pre_query = Build.filter_active(
|
||||
Build.id == token_dict.selected_occupant.build_id
|
||||
Build.pre_query = Build.filter_all(
|
||||
Build.id == token_dict.selected_occupant.build_id,
|
||||
Build.active == True,
|
||||
).query
|
||||
elif isinstance(token_dict, EmployeeTokenObject):
|
||||
Build.pre_query = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id
|
||||
)
|
||||
Build.filter_attr = list_options
|
||||
records = Build.filter_active(
|
||||
*Build.get_smart_query(smart_query=list_options.query)
|
||||
records = Build.filter_all(
|
||||
*Build.get_smart_query(smart_query=list_options.query),
|
||||
Build.active == True,
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
@@ -81,13 +83,13 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||
|
||||
created_build = Build.create_action(data=data, token=token_dict)
|
||||
if not created_build.is_found:
|
||||
build_type = BuildTypes.find_one(type_code="APT_YNT")
|
||||
build_type = BuildTypes.filter_by_one(type_code="APT_YNT").data
|
||||
if not build_type:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Build type APT_YNT is not found. Please contact with your system administrator.",
|
||||
)
|
||||
api_enum = ApiEnumDropdown.find_one(enum_class="Directions", key="NN")
|
||||
api_enum = ApiEnumDropdown.filter_by_one(enum_class="Directions", key="NN").data
|
||||
if not api_enum:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
@@ -107,8 +109,8 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||
is_confirmed=True,
|
||||
)
|
||||
man_build_part = BuildParts.find_or_create(**build_parts)
|
||||
if not man_build_part.is_found:
|
||||
created_build.update(management_room_id=man_build_part.id)
|
||||
created_build.update(management_room_id=man_build_part.id)
|
||||
BuildParts.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
@@ -148,24 +150,19 @@ class BuildCreateEventMethods(MethodToEvent):
|
||||
)
|
||||
|
||||
created_build = Build.create_action(data=data, token=token_dict)
|
||||
if not created_build.is_found:
|
||||
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,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Create Build record completed. This build is assigned to you.",
|
||||
"data": created_build.get_dict(),
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail=f"Build record create not successful for {token_dict.selected_company.employee_uu_id}",
|
||||
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,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Create Build record completed. This build is assigned to you.",
|
||||
"data": created_build.get_dict(),
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
|
||||
|
||||
@@ -181,10 +178,12 @@ class BuildUpdateEventMethods(MethodToEvent):
|
||||
Build.pre_query = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id
|
||||
)
|
||||
if Build.filter_active(Build.person_id == token_dict.person_id):
|
||||
if Build.filter_all(Build.person_id == token_dict.person_id):
|
||||
Build.pre_query = None
|
||||
if updated_build := Build.update_action(
|
||||
data=data, token=token_dict, build_uu_id=build_uu_id
|
||||
):
|
||||
Build.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
|
||||
Reference in New Issue
Block a user