alchemy functions updated
This commit is contained in:
parent
e01a2c8afb
commit
7a7241c71c
|
|
@ -10,7 +10,6 @@ from databases import (
|
|||
AddressStreet,
|
||||
)
|
||||
|
||||
|
||||
from api_validations.validations_request import (
|
||||
ListOptions,
|
||||
InsertAddress,
|
||||
|
|
@ -38,8 +37,6 @@ class AddressListEventMethods(MethodToEvent):
|
|||
list_options: ListOptions,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
from sqlalchemy import select
|
||||
|
||||
post_code_list = RelationshipEmployee2PostCode.filter_all(
|
||||
RelationshipEmployee2PostCode.company_id
|
||||
== token_dict.selected_company.company_id,
|
||||
|
|
@ -55,7 +52,7 @@ class AddressListEventMethods(MethodToEvent):
|
|||
street_id[0]
|
||||
for street_id in AddressPostcode.select_only(
|
||||
AddressPostcode.id.in_(post_code_id_list),
|
||||
AddressPostcode.active == True,
|
||||
*AddressPostcode.valid_record_args(AddressPostcode),
|
||||
select_args=[AddressPostcode.street_id],
|
||||
order_by=AddressPostcode.street_id.desc(),
|
||||
).data
|
||||
|
|
@ -67,14 +64,14 @@ class AddressListEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
Addresses.pre_query = Addresses.filter_all(
|
||||
Addresses.street_id.in_(*get_street_ids),
|
||||
Addresses.active == True,
|
||||
Addresses.street_id.in_(get_street_ids),
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).query
|
||||
Addresses.filter_attr = list_options
|
||||
records = Addresses.filter_all(
|
||||
*Addresses.get_smart_query(list_options.query),
|
||||
Addresses.active == True,
|
||||
)
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="List Address records",
|
||||
|
|
@ -114,7 +111,7 @@ class AddressCreateEventMethods(MethodToEvent):
|
|||
):
|
||||
post_code = AddressPostcode.filter_one(
|
||||
AddressPostcode.uu_id == data.post_code_uu_id,
|
||||
AddressPostcode.active == True,
|
||||
*AddressPostcode.valid_record_args(AddressPostcode),
|
||||
).data
|
||||
if not post_code:
|
||||
raise HTTPException(
|
||||
|
|
@ -230,9 +227,15 @@ class AddressUpdateEventMethods(MethodToEvent):
|
|||
data: InsertAddress,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
address = Addresses.find_one_or_abort(uu_id=address_uu_id)
|
||||
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.member_id == address.post_code_id,
|
||||
*RelationshipEmployee2PostCode.valid_record_args(
|
||||
RelationshipEmployee2PostCode
|
||||
),
|
||||
).data
|
||||
if not post_code:
|
||||
raise HTTPException(
|
||||
|
|
@ -270,9 +273,15 @@ class AddressPatchEventMethods(MethodToEvent):
|
|||
data: InsertAddress,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
address = Addresses.find_one_or_abort(uu_id=address_uu_id)
|
||||
address = Addresses.filter_one(
|
||||
Addresses.uu_id == address_uu_id,
|
||||
*Addresses.valid_record_args(Addresses),
|
||||
).data
|
||||
post_code = RelationshipEmployee2PostCode.filter_one(
|
||||
RelationshipEmployee2PostCode.member_id == address.post_code_id
|
||||
RelationshipEmployee2PostCode.member_id == address.post_code_id,
|
||||
*RelationshipEmployee2PostCode.valid_record_args(
|
||||
RelationshipEmployee2PostCode
|
||||
),
|
||||
)
|
||||
if not post_code:
|
||||
raise HTTPException(
|
||||
|
|
@ -309,7 +318,10 @@ class AddressPostCodeCreateEventMethods(MethodToEvent):
|
|||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
data_dump = data.excluded_dump()
|
||||
street = AddressStreet.filter_one(AddressStreet.uu_id == data.street_uu_id).data
|
||||
street = AddressStreet.filter_one(
|
||||
AddressStreet.uu_id == data.street_uu_id,
|
||||
*AddressStreet.valid_record_args(AddressStreet),
|
||||
).data
|
||||
if not street:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
|
|
@ -390,7 +402,8 @@ class AddressPostCodeListEventMethods(MethodToEvent):
|
|||
):
|
||||
post_code_list = AddressPostcode.__many__table__.filter_all(
|
||||
AddressPostcode.__many__table__.company_id
|
||||
== token_dict.selected_company.company_id
|
||||
== token_dict.selected_company.company_id,
|
||||
*AddressPostcode.valid_record_args(AddressPostcode.__many__table__),
|
||||
).data
|
||||
if not post_code_list:
|
||||
raise HTTPException(
|
||||
|
|
@ -402,11 +415,12 @@ class AddressPostCodeListEventMethods(MethodToEvent):
|
|||
AddressPostcode.id.in_(
|
||||
[post_code.member_id for post_code in post_code_list]
|
||||
),
|
||||
AddressPostcode.active == True,
|
||||
*AddressPostcode.valid_record_args(AddressPostcode),
|
||||
).query
|
||||
AddressPostcode.filter_attr = list_options
|
||||
records = AddressPostcode.filter_all(
|
||||
*Addresses.get_smart_query(list_options.query)
|
||||
*Addresses.get_smart_query(list_options.query),
|
||||
*Addresses.valid_record_args(AddressPostcode),
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ from databases import (
|
|||
BuildLivingSpace,
|
||||
BuildParts,
|
||||
Build,
|
||||
RelationshipEmployee2PostCode,
|
||||
Duty,
|
||||
Event2Occupant,
|
||||
Event2Employee,
|
||||
|
|
@ -37,7 +36,7 @@ from api_services import (
|
|||
|
||||
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, system_arrow
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from api_configs import ApiStatic, Auth
|
||||
from databases.no_sql_models.login_handlers import load_user_with_erp_details
|
||||
|
||||
|
|
@ -114,11 +113,15 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
},
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
)
|
||||
if selected_company := Companies.find_one(uu_id=data.company_uu_id):
|
||||
if selected_company := Companies.filter_one(
|
||||
Companies.uu_id == data.company_uu_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data:
|
||||
department_ids = [
|
||||
department.id
|
||||
for department in Departments.filter_all(
|
||||
Departments.company_id == selected_company.id
|
||||
Departments.company_id == selected_company.id,
|
||||
*Departments.valid_record_args(Departments),
|
||||
).data
|
||||
]
|
||||
duties_ids = [
|
||||
|
|
@ -126,29 +129,41 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
for duties in Duties.filter_all(
|
||||
Duties.company_id == selected_company.id,
|
||||
Duties.department_id.in_(department_ids),
|
||||
*Duties.valid_record_args(Duties),
|
||||
).data
|
||||
]
|
||||
staff_ids = [
|
||||
staff.id
|
||||
for staff in Staff.filter_all(Staff.duties_id.in_(duties_ids)).data
|
||||
for staff in Staff.filter_all(
|
||||
Staff.duties_id.in_(duties_ids), *Staff.valid_record_args(Staff)
|
||||
).data
|
||||
]
|
||||
employee = Employees.filter_one(
|
||||
Employees.people_id == token_user.person_id,
|
||||
Employees.staff_id.in_(staff_ids),
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
|
||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
|
||||
)
|
||||
staff = Staff.filter_one(Staff.id == employee.staff_id).data
|
||||
duties = Duties.find_one(Duties.id == staff.duties_id).data
|
||||
department = Departments.find_one(
|
||||
Departments.id == duties.department_id
|
||||
staff = Staff.filter_one(
|
||||
Staff.id == employee.staff_id, *Staff.valid_record_args(Staff)
|
||||
).data
|
||||
duties = Duties.find_one(
|
||||
Duties.id == staff.duties_id, *Duties.valid_record_args(Duties)
|
||||
).data
|
||||
department = Departments.find_one(
|
||||
Departments.id == duties.department_id,
|
||||
*Departments.valid_record_args(Departments),
|
||||
).data
|
||||
bulk_id = Duty.filter_one(
|
||||
Duty.duty_code == "BULK", *Duty.valid_record_args(Duty)
|
||||
).data
|
||||
bulk_id = Duty.filter_one(Duty.duty_code == "BULK").data
|
||||
bulk_duty_id = Duties.filter_one(
|
||||
Duties.company_id == selected_company.id,
|
||||
Duties.duties_id == bulk_id.id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
).data
|
||||
update_selected_to_redis(
|
||||
request=request,
|
||||
|
|
@ -185,27 +200,36 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
detail="Occupant Type is not found",
|
||||
)
|
||||
build_part = BuildParts.filter_one(
|
||||
BuildParts.uu_id == data.build_part_uu_id
|
||||
BuildParts.uu_id == data.build_part_uu_id,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).data
|
||||
if not build_part:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail="Build Part is not found",
|
||||
)
|
||||
build = Build.filter_one(Build.id == build_part.build_id).data
|
||||
build = Build.filter_one(
|
||||
Build.id == build_part.build_id, *Build.valid_record_args(Build)
|
||||
).data
|
||||
related_company = RelationshipEmployee2Build.filter_one(
|
||||
RelationshipEmployee2Build.member_id == build.id
|
||||
RelationshipEmployee2Build.member_id == build.id,
|
||||
*RelationshipEmployee2Build.valid_record_args(
|
||||
RelationshipEmployee2Build
|
||||
),
|
||||
).data
|
||||
company_related = Companies.filter_one(
|
||||
Companies.id == related_company.company_id
|
||||
Companies.id == related_company.company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data
|
||||
responsible_employee = Employees.filter_one(
|
||||
Employees.id == related_company.employee_id
|
||||
Employees.id == related_company.employee_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
if selected_occupant_type := BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.occupant_type == occupant_type.id,
|
||||
BuildLivingSpace.person_id == token_user.person_id,
|
||||
BuildLivingSpace.build_parts_id == build_part.id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data:
|
||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||
Event2Occupant.get_event_id_by_build_living_space_id(
|
||||
|
|
@ -292,6 +316,7 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
|
|||
UsersTokens.domain == found_user.domain_name,
|
||||
UsersTokens.user_id == found_user.id,
|
||||
UsersTokens.token_type == "RememberMe",
|
||||
*UsersTokens.valid_record_args(UsersTokens),
|
||||
).data
|
||||
access_dict = {
|
||||
"access_token": access_token,
|
||||
|
|
@ -327,7 +352,9 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
|||
):
|
||||
token_user = get_object_via_access_key(request=request)
|
||||
if token_user.user_type == 1:
|
||||
if found_user := Users.filter_one(Users.uu_id == token_user.uu_id).data:
|
||||
if found_user := Users.filter_one(
|
||||
Users.uu_id == token_user.uu_id, *Users.valid_record_args(Users)
|
||||
).data:
|
||||
if found_user.check_password(data.old_password):
|
||||
found_user.set_password(data.new_password)
|
||||
return JSONResponse(
|
||||
|
|
@ -367,7 +394,7 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
|
||||
)
|
||||
if found_user := Users.filter_one(
|
||||
Users.password_token == data.password_token
|
||||
Users.password_token == data.password_token, *Users.valid_record_args(Users)
|
||||
).data:
|
||||
found_user.create_password(password=data.password)
|
||||
found_user.password_token = None
|
||||
|
|
@ -412,7 +439,9 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
|||
):
|
||||
|
||||
if token_user := get_object_via_access_key(request=request):
|
||||
found_user = Users.filter_one(Users.uu_id == token_user.get("uu_id")).data
|
||||
found_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id"), *Users.valid_record_args(Users)
|
||||
).data
|
||||
if not found_user:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -427,7 +456,8 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
|||
token_user = json.loads(redis_cli.get(key) or {})
|
||||
redis_cli.delete(key)
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id")
|
||||
Users.uu_id == token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
).data
|
||||
selected_user.remove_refresher_token(
|
||||
domain=data.domain, disconnect=True
|
||||
|
|
@ -478,7 +508,8 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
|||
if token_user.get("domain") == data.domain:
|
||||
redis_cli.delete(key)
|
||||
selected_user = Users.filter_one(
|
||||
Users.uu_id == token_user.get("uu_id")
|
||||
Users.uu_id == token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
).data
|
||||
selected_user.remove_refresher_token(domain=data.domain)
|
||||
# UserLogger.log_error(
|
||||
|
|
@ -533,7 +564,9 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
|||
content={"completed": False, "message": "Invalid data", "data": {}},
|
||||
status_code=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
if found_user := Users.filter_one(Users.id == token_refresher.user_id).data:
|
||||
if found_user := Users.filter_one(
|
||||
Users.id == token_refresher.user_id, *Users.valid_record_args(Users)
|
||||
).data:
|
||||
found_user: Users = found_user
|
||||
access_key = save_access_token_to_redis(
|
||||
request=request, found_user=found_user, domain=data.domain
|
||||
|
|
|
|||
|
|
@ -144,21 +144,23 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
Event2Employee.get_event_id_by_employee_id(employee_id=employee.id)
|
||||
)
|
||||
staff = Staff.filter_one(
|
||||
Staff.id==employee.staff_id,
|
||||
Staff.id == employee.staff_id,
|
||||
*Staff.valid_record_args(Staff),
|
||||
).data
|
||||
duties = Duties.filter_one(
|
||||
Duties.id==staff.duties_id,
|
||||
Duties.id == staff.duties_id,
|
||||
*Duties.valid_record_args(Duties),
|
||||
).data
|
||||
department = Departments.filter_one(
|
||||
Departments.id==duties.department_id,
|
||||
Departments.id == duties.department_id,
|
||||
).data
|
||||
bulk_id = Duty.filter_by_one(
|
||||
duty_code="BULK", *Duty.valid_record_args(Duty)
|
||||
).data
|
||||
bulk_duty_id = Duties.filter_by_one(
|
||||
company_id=selected_company.id, duties_id=bulk_id.id, *Duties.valid_record_dict
|
||||
company_id=selected_company.id,
|
||||
duties_id=bulk_id.id,
|
||||
*Duties.valid_record_dict,
|
||||
).data
|
||||
update_selected_to_redis(
|
||||
request=request,
|
||||
|
|
@ -199,25 +201,27 @@ class AuthenticationSelectEventMethods(MethodToEvent):
|
|||
detail="Build Part is not found",
|
||||
)
|
||||
build = Build.filter_one(
|
||||
Build.id==build_part.build_id,
|
||||
Build.id == build_part.build_id,
|
||||
*Build.valid_record_args(Build),
|
||||
).data
|
||||
related_company = RelationshipEmployee2Build.filter_one(
|
||||
RelationshipEmployee2Build.member_id==build.id,
|
||||
*RelationshipEmployee2Build.valid_record_args(RelationshipEmployee2Build),
|
||||
RelationshipEmployee2Build.member_id == build.id,
|
||||
*RelationshipEmployee2Build.valid_record_args(
|
||||
RelationshipEmployee2Build
|
||||
),
|
||||
).data
|
||||
company_related = Companies.filter_one(
|
||||
Companies.id==related_company.company_id,
|
||||
Companies.id == related_company.company_id,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).data
|
||||
responsible_employee = Employees.find_one(
|
||||
Employees.id==related_company.employee_id,
|
||||
Employees.id == related_company.employee_id,
|
||||
*Employees.valid_record_args(Employees),
|
||||
).data
|
||||
if selected_occupant_type := BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.occupant_type==occupant_type.id,
|
||||
BuildLivingSpace.person_id==token_user.person_id,
|
||||
BuildLivingSpace.build_parts_id==build_part.id,
|
||||
BuildLivingSpace.occupant_type == occupant_type.id,
|
||||
BuildLivingSpace.person_id == token_user.person_id,
|
||||
BuildLivingSpace.build_parts_id == build_part.id,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data:
|
||||
reachable_event_list_id, reachable_event_list_uu_id = (
|
||||
|
|
@ -293,13 +297,13 @@ class AuthenticationRefreshEventMethods(MethodToEvent):
|
|||
access_token = str(request.headers.get(Auth.ACCESS_TOKEN_TAG))
|
||||
if token_user := get_object_via_access_key(request=request):
|
||||
if found_user := Users.filter_one(
|
||||
Users.uu_id==token_user.get("uu_id"),
|
||||
Users.uu_id == token_user.get("uu_id"),
|
||||
*Users.valid_record_args(Users),
|
||||
).data:
|
||||
user_token = UsersTokens.filter_one(
|
||||
UsersTokens.domain==found_user.domain_name,
|
||||
UsersTokens.user_id==found_user.id,
|
||||
UsersTokens.token_type=="RememberMe",
|
||||
UsersTokens.domain == found_user.domain_name,
|
||||
UsersTokens.user_id == found_user.id,
|
||||
UsersTokens.token_type == "RememberMe",
|
||||
*UsersTokens.valid_record_args(UsersTokens),
|
||||
).data
|
||||
access_dict = {
|
||||
|
|
@ -329,11 +333,13 @@ class AuthenticationChangePasswordEventMethods(MethodToEvent):
|
|||
|
||||
@classmethod
|
||||
def authentication_change_password(
|
||||
cls, data: ChangePassword, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
cls,
|
||||
data: ChangePassword,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
if token_dict.user_type == 1:
|
||||
if found_user := Users.filter_one(
|
||||
Users.uu_id==token_dict.person_uu_id,
|
||||
Users.uu_id == token_dict.person_uu_id,
|
||||
*Users.valid_record_args(Users),
|
||||
).data:
|
||||
if found_user.check_password(data.old_password):
|
||||
|
|
@ -366,15 +372,13 @@ class AuthenticationCreatePasswordEventMethods(MethodToEvent):
|
|||
}
|
||||
|
||||
@classmethod
|
||||
def authentication_create_password(
|
||||
cls, data: CreatePassword
|
||||
):
|
||||
def authentication_create_password(cls, data: CreatePassword):
|
||||
if not data.re_password == data.password:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE, detail="Password must match"
|
||||
)
|
||||
if found_user := Users.filter_one(
|
||||
Users.password_token==data.password_token,
|
||||
Users.password_token == data.password_token,
|
||||
*Users.valid_record_args(Users),
|
||||
).data:
|
||||
found_user.create_password(password=data.password)
|
||||
|
|
@ -416,10 +420,13 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
|
|||
|
||||
@classmethod
|
||||
def authentication_disconnect_user(
|
||||
cls, request: Request, data: Logout, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
cls,
|
||||
request: Request,
|
||||
data: Logout,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
found_user = Users.filter_one(
|
||||
Users.uu_id==token_dict.person_uu_id,
|
||||
Users.uu_id == token_dict.person_uu_id,
|
||||
*Users.valid_record_args(Users),
|
||||
).data
|
||||
if not found_user:
|
||||
|
|
@ -479,6 +486,7 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
|||
cls, data: Logout, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
):
|
||||
from api_services.redis.functions import get_object_via_user_uu_id
|
||||
|
||||
if not token_dict:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -519,7 +527,6 @@ class AuthenticationLogoutEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
|
||||
|
||||
class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
||||
|
||||
event_type = "UPDATE"
|
||||
|
|
@ -540,7 +547,7 @@ class AuthenticationRefreshTokenEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_202_ACCEPTED,
|
||||
)
|
||||
if found_user := Users.filter_one(
|
||||
Users.id==token_refresher.user_id,
|
||||
Users.id == token_refresher.user_id,
|
||||
*Users.valid_record_args(Users),
|
||||
):
|
||||
found_user: Users = found_user
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class BuildListEventMethods(MethodToEvent):
|
|||
if isinstance(token_dict, OccupantTokenObject):
|
||||
Build.pre_query = Build.filter_all(
|
||||
Build.id == token_dict.selected_occupant.build_id,
|
||||
Build.active == True,
|
||||
*Build.valid_record_args(Build),
|
||||
).query
|
||||
elif isinstance(token_dict, EmployeeTokenObject):
|
||||
Build.pre_query = Build.select_action(
|
||||
|
|
@ -50,8 +50,8 @@ class BuildListEventMethods(MethodToEvent):
|
|||
Build.filter_attr = list_options
|
||||
records = Build.filter_all(
|
||||
*Build.get_smart_query(smart_query=list_options.query),
|
||||
Build.active == True,
|
||||
)
|
||||
*Build.valid_record_args(Build),
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
message="Building Records are listed",
|
||||
|
|
@ -82,16 +82,16 @@ class BuildCreateEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
created_build = Build.create_action(data=data, token=token_dict)
|
||||
if not created_build.is_found:
|
||||
build_type = BuildTypes.filter_by_one(type_code="APT_YNT", *BuildTypes.valid_record_dict).data
|
||||
|
||||
build_type = BuildTypes.filter_by_one(
|
||||
type_code="APT_YNT", *BuildTypes.valid_record_dict
|
||||
).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.filter_by_one(
|
||||
enum_class="Directions", key="NN"
|
||||
).data
|
||||
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,
|
||||
|
|
@ -121,10 +121,6 @@ class BuildCreateEventMethods(MethodToEvent):
|
|||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
detail=f"Build record create not successful for Employee UUID : {token_dict.selected_company.employee_uu_id}",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def create_building_employee(
|
||||
|
|
@ -132,8 +128,8 @@ class BuildCreateEventMethods(MethodToEvent):
|
|||
):
|
||||
records = Addresses.list_via_employee(
|
||||
token_dict=token_dict, filter_expr=[Addresses.uu_id == data.address_uu_id]
|
||||
)
|
||||
if not records.data:
|
||||
).data
|
||||
if not records:
|
||||
raise HTTPException(
|
||||
status_code=404,
|
||||
detail=f"This address {data.address_uu_id} is not found in the user's address list.",
|
||||
|
|
@ -180,11 +176,14 @@ class BuildUpdateEventMethods(MethodToEvent):
|
|||
Build.pre_query = Build.select_action(
|
||||
employee_id=token_dict.selected_company.employee_id
|
||||
)
|
||||
if Build.filter_all(Build.person_id == token_dict.person_id):
|
||||
if Build.filter_all(
|
||||
Build.person_id == token_dict.person_id,
|
||||
*Build.valid_record_args(Build),
|
||||
).data:
|
||||
Build.pre_query = None
|
||||
if updated_build := Build.update_action(
|
||||
updated_build = Build.update_action(
|
||||
data=data, token=token_dict, build_uu_id=build_uu_id
|
||||
):
|
||||
)
|
||||
Build.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
|
|||
|
|
@ -35,10 +35,12 @@ class BuildingBuildPartsListEventMethods(MethodToEvent):
|
|||
)
|
||||
build_list_ids = [build.id for build in build_list_query.all()]
|
||||
BuildParts.pre_query = BuildParts.query.filter(
|
||||
BuildParts.build_id.in_(build_list_ids)
|
||||
BuildParts.build_id.in_(build_list_ids),
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
)
|
||||
records = BuildParts.filter_active(
|
||||
*BuildParts.get_smart_query(list_options.query)
|
||||
*BuildParts.get_smart_query(list_options.query),
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
|
|
@ -61,15 +63,6 @@ class BuildingBuildPartsCreateEventMethods(MethodToEvent):
|
|||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
created_build = BuildParts.create_action(data=data, token=token_dict)
|
||||
if not created_build:
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": False,
|
||||
"message": "Create Build Parts is not completed",
|
||||
"data": {},
|
||||
},
|
||||
status_code=status.HTTP_406_NOT_ACCEPTABLE,
|
||||
)
|
||||
created_build.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -94,7 +87,7 @@ class BuildingBuildPartsUpdateEventMethods(MethodToEvent):
|
|||
data: InsertBuildParts,
|
||||
token_dict: Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
if updated_build := BuildParts.update_action(data=data, token=token_dict):
|
||||
updated_build = BuildParts.update_action(data=data, token=token_dict)
|
||||
updated_build.save()
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -104,14 +97,6 @@ class BuildingBuildPartsUpdateEventMethods(MethodToEvent):
|
|||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
return JSONResponse(
|
||||
content={
|
||||
"completed": True,
|
||||
"message": "Update Build Parts record",
|
||||
"data": {},
|
||||
},
|
||||
status_code=status.HTTP_200_OK,
|
||||
)
|
||||
|
||||
|
||||
class BuildingBuildPartsPatchEventMethods(MethodToEvent):
|
||||
|
|
@ -123,7 +108,10 @@ class BuildingBuildPartsPatchEventMethods(MethodToEvent):
|
|||
|
||||
@classmethod
|
||||
def building_build_parts_patch(cls, data, token_dict):
|
||||
find_one_build = BuildParts.filter_one(BuildParts.uu_id == data.uu_id).data
|
||||
find_one_build = BuildParts.filter_one(
|
||||
BuildParts.uu_id == data.uu_id,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).data
|
||||
access_authorized_build = BuildParts.select_action(
|
||||
duty_id=token_dict.selected_company.duty_id,
|
||||
filter_expr=[BuildParts.id == find_one_build.id],
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
|||
Build.filter_attr = list_options
|
||||
build_part_id_list_query = BuildParts.filter_all(
|
||||
BuildParts.build_id.in_([build.id for build in build_id_list_query.all()]),
|
||||
BuildParts.active == True,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).data
|
||||
|
||||
list_options.query.pop("expiry_starts", None)
|
||||
|
|
@ -47,8 +47,8 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
|||
BuildLivingSpace.build_parts_id.in_(
|
||||
[build_part.id for build_part in build_part_id_list_query]
|
||||
),
|
||||
BuildLivingSpace.active == True,
|
||||
*BuildLivingSpace.get_smart_query(smart_query=list_options.query),
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
)
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
|
|
@ -66,7 +66,7 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
|||
Build.filter_attr = list_options
|
||||
build_part_id_list_query = BuildParts.filter_all(
|
||||
BuildParts.build_id.in_([build.id for build in build_id_list_query.all()]),
|
||||
BuildParts.active == True,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
|
||||
records = BuildLivingSpace.filter_all(
|
||||
|
|
@ -74,6 +74,7 @@ class BuildingLivingSpacesPartsListEventMethods(MethodToEvent):
|
|||
[build_part.id for build_part in build_part_id_list_query]
|
||||
),
|
||||
*BuildLivingSpace.get_smart_query(smart_query=list_options.query),
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
|
|
@ -96,7 +97,6 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
|||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
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(
|
||||
|
|
@ -105,6 +105,7 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
|||
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()]),
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
if not build_part:
|
||||
raise HTTPException(
|
||||
|
|
@ -112,7 +113,10 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
|||
detail=f"{data.build_parts_uu_id} - Build Part is not found in database. Check build part uu_id",
|
||||
)
|
||||
|
||||
life_person = People.filter_one(People.uu_id == data.person_uu_id or "").data
|
||||
life_person = People.filter_one(
|
||||
People.uu_id == data.person_uu_id or "",
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
if not life_person:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_418_IM_A_TEAPOT,
|
||||
|
|
@ -139,17 +143,17 @@ class BuildingLivingSpacesPartsCreateEventMethods(MethodToEvent):
|
|||
BuildLivingSpace.build_parts_id == build_part.id,
|
||||
BuildLivingSpace.person_id == life_person.id,
|
||||
BuildLivingSpace.occupant_type == occupant_type.id,
|
||||
BuildLivingSpace.active == True,
|
||||
BuildLivingSpace.is_confirmed == True,
|
||||
str(system_arrow.now()) < BuildLivingSpace.expiry_ends,
|
||||
str(system_arrow.now()) >= BuildLivingSpace.expiry_starts,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
# str(system_arrow.now()) < BuildLivingSpace.expiry_ends,
|
||||
# str(system_arrow.now()) >= BuildLivingSpace.expiry_starts,
|
||||
select_args=[BuildLivingSpace.id],
|
||||
order_by=BuildLivingSpace.expiry_starts.desc(),
|
||||
limit=1,
|
||||
).data
|
||||
|
||||
last_living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == living_space_id[0] if living_space_id else None
|
||||
BuildLivingSpace.id == living_space_id[0] if living_space_id else None,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
)
|
||||
|
||||
data_dict["expiry_starts"] = str(system_arrow.now())
|
||||
|
|
@ -183,7 +187,6 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
|||
@classmethod
|
||||
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()
|
||||
build_id_list_query = Build.select_action(
|
||||
|
|
@ -192,7 +195,7 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
|||
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()]),
|
||||
BuildParts.active == True,
|
||||
*BuildParts.valid_record_args(BuildParts),
|
||||
).data
|
||||
if not build_part:
|
||||
raise HTTPException(
|
||||
|
|
@ -211,13 +214,15 @@ class BuildingLivingSpacesPartsUpdateEventMethods(MethodToEvent):
|
|||
)
|
||||
|
||||
living_space_id = BuildLivingSpace.select_only(
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
select_args=[BuildLivingSpace.id],
|
||||
order_by=BuildLivingSpace.expiry_starts.desc(),
|
||||
limit=1,
|
||||
).get(1)
|
||||
|
||||
last_living_space = BuildLivingSpace.filter_one(
|
||||
BuildLivingSpace.id == living_space_id if living_space_id else None
|
||||
BuildLivingSpace.id == living_space_id if living_space_id else None,
|
||||
*BuildLivingSpace.valid_record_args(BuildLivingSpace),
|
||||
).data
|
||||
|
||||
data_dict["expiry_starts"] = str(system_arrow.now())
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from api_validations.validations_request 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 AlchemyJsonResponse
|
||||
from api_library.date_time_actions.date_functions import DateTimeLocal, system_arrow
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
|
||||
|
||||
class DecisionBookListEventMethods(MethodToEvent):
|
||||
|
|
@ -49,13 +49,13 @@ class DecisionBookListEventMethods(MethodToEvent):
|
|||
records = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id.in_([build.id for build in build_id_list]),
|
||||
*BuildDecisionBook.get_smart_query(list_options.query),
|
||||
BuildDecisionBook.active == True,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data
|
||||
elif isinstance(token_dict, OccupantTokenObject):
|
||||
records = BuildDecisionBook.filter_all(
|
||||
BuildDecisionBook.build_id == token_dict.selected_occupant.build_id,
|
||||
*BuildDecisionBook.get_smart_query(list_options.query),
|
||||
BuildDecisionBook.active == True,
|
||||
*BuildDecisionBook.valid_record_args(BuildDecisionBook),
|
||||
).data
|
||||
return AlchemyJsonResponse(
|
||||
completed=True,
|
||||
|
|
@ -101,7 +101,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
|||
)
|
||||
company = Companies.filter_one(
|
||||
Companies.uu_id == data.resp_company_uu_id,
|
||||
Companies.active == True,
|
||||
*Companies.valid_record_args(Companies),
|
||||
).get(1)
|
||||
if not company:
|
||||
raise HTTPException(
|
||||
|
|
@ -111,8 +111,8 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
|||
data_dict["resp_company_id"] = company.id
|
||||
data_dict["resp_company_uu_id"] = str(company.uu_id)
|
||||
|
||||
decision_period_date = DateTimeLocal.get(build.decision_period_date)
|
||||
data_dict["expiry_starts"] = DateTimeLocal.get(
|
||||
decision_period_date = system_arrow.get(build.decision_period_date)
|
||||
data_dict["expiry_starts"] = system_arrow.get(
|
||||
system_arrow.now().date().year,
|
||||
int(decision_period_date.date().month),
|
||||
int(decision_period_date.date().day),
|
||||
|
|
@ -143,7 +143,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
|||
|
||||
occupant_build = Build.filter_one(
|
||||
Build.id == token_dict.selected_occupant.build_id,
|
||||
Build.active == True,
|
||||
*Build.valid_record_args(Build),
|
||||
).get(1)
|
||||
occupant_company = Companies.find_one(
|
||||
Companies.id == token_dict.selected_occupant.responsible_company_id,
|
||||
|
|
@ -155,7 +155,7 @@ class DecisionBookCreateEventMethods(MethodToEvent):
|
|||
data_dict["resp_company_uu_id"] = str(occupant_company.uu_id)
|
||||
|
||||
decision_period_date = system_arrow.get(occupant_build.decision_period_date)
|
||||
data_dict["expiry_starts"] = DateTimeLocal.get(
|
||||
data_dict["expiry_starts"] = system_arrow.get(
|
||||
system_arrow.now().date().year,
|
||||
int(decision_period_date.date().month),
|
||||
int(decision_period_date.date().day),
|
||||
|
|
|
|||
|
|
@ -235,7 +235,9 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
|||
detail="Occupant is not authorized to add service to any employee",
|
||||
)
|
||||
|
||||
employee = Employees.filter_by_one(uu_id=data.employee_uu_id, *Employees.valid_record_dict).data
|
||||
employee = Employees.filter_by_one(
|
||||
uu_id=data.employee_uu_id, *Employees.valid_record_dict
|
||||
).data
|
||||
if not employee:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
@ -246,7 +248,9 @@ class ServiceBindEmployeeEventMethods(MethodToEvent):
|
|||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
)
|
||||
|
||||
service = Services.filter_by_one(uu_id=data.service_uu_id, *Services.valid_record_dict).data
|
||||
service = Services.filter_by_one(
|
||||
uu_id=data.service_uu_id, *Services.valid_record_dict
|
||||
).data
|
||||
if not service:
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ class UserUpdateEventMethods(MethodToEvent):
|
|||
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
|
||||
):
|
||||
find_one_user = Users.filter_one(
|
||||
Users.uu_id==user_uu_id,
|
||||
Users.uu_id == user_uu_id,
|
||||
*Users.valid_record_args(Users),
|
||||
).data
|
||||
access_authorized_company = Companies.select_action(
|
||||
|
|
@ -158,7 +158,7 @@ class UserPatchEventMethods(MethodToEvent):
|
|||
@classmethod
|
||||
def user_patch(cls, data: PatchRecord, user_uu_id: str, token_dict):
|
||||
find_one_user = Users.filter_one(
|
||||
Users.uu_id==user_uu_id,
|
||||
Users.uu_id == user_uu_id,
|
||||
*Users.valid_record_args(Users),
|
||||
).data
|
||||
access_authorized_company = Companies.select_action(
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ class BuildDecisionBookPerson(CrudCollection):
|
|||
if build_living_space_id:
|
||||
related_service = Services.filter_by_one(
|
||||
related_responsibility=str(occupant_type.occupant_code),
|
||||
*Services.valid_record_dict
|
||||
*Services.valid_record_dict,
|
||||
)
|
||||
if not related_service:
|
||||
raise HTTPException(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import datetime
|
||||
from decimal import Decimal
|
||||
from typing import Union
|
||||
|
||||
from sqlalchemy import (
|
||||
TIMESTAMP,
|
||||
|
|
@ -23,6 +24,7 @@ from sqlalchemy_mixins.repr import ReprMixin
|
|||
from sqlalchemy_mixins.smartquery import SmartQueryMixin
|
||||
|
||||
from api_library.date_time_actions.date_functions import DateTimeLocal, client_arrow
|
||||
from api_objects import EmployeeTokenObject, OccupantTokenObject
|
||||
from api_objects.auth.token_objects import Credentials
|
||||
|
||||
from databases.sql_models.sql_operations import FilterAttributes
|
||||
|
|
@ -90,6 +92,13 @@ class CrudMixin(Base, SmartQueryMixin, SessionMixin, FilterAttributes):
|
|||
TIMESTAMP, default="2099-12-31", server_default="2099-12-31"
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def set_user_define_properties(
|
||||
cls, token: Union[EmployeeTokenObject, OccupantTokenObject]
|
||||
):
|
||||
cls.creds = token.credentials
|
||||
cls.client_arrow = DateTimeLocal(is_client=True, timezone=token.timezone)
|
||||
|
||||
@classmethod
|
||||
def remove_non_related_inputs(cls, kwargs):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -182,13 +182,12 @@ class Event2Occupant(CrudCollection):
|
|||
cls, build_living_space_id
|
||||
) -> (list, list):
|
||||
active_events = cls.filter_all(
|
||||
cls.build_living_space_id==build_living_space_id,
|
||||
*cls.valid_record_args(cls)
|
||||
cls.build_living_space_id == build_living_space_id,
|
||||
*cls.valid_record_args(cls),
|
||||
).data
|
||||
active_events_id = [event.event_id for event in active_events]
|
||||
active_events = Events.filter_all(
|
||||
Events.id.in_(active_events_id),
|
||||
*Events.valid_record_args(Events)
|
||||
Events.id.in_(active_events_id), *Events.valid_record_args(Events)
|
||||
).data
|
||||
active_events_uu_id = [str(event.uu_id) for event in active_events]
|
||||
return active_events_id, active_events_uu_id
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from api_library.date_time_actions.date_functions import DateTimeLocal
|
||||
from api_library.date_time_actions.date_functions import system_arrow
|
||||
from api_configs import Auth, ApiStatic, RelationAccess
|
||||
|
||||
from datetime import timedelta
|
||||
|
|
@ -37,7 +37,7 @@ class UsersTokens(CrudCollection):
|
|||
token_type: Mapped[str] = mapped_column(String(16), server_default="RememberMe")
|
||||
token: Mapped[str] = mapped_column(String, server_default="")
|
||||
domain: Mapped[str] = mapped_column(String, server_default="")
|
||||
expires_at = mapped_column(TIMESTAMP, default=str(DateTimeLocal.shift(days=3)))
|
||||
expires_at = mapped_column(TIMESTAMP, default=str(system_arrow.shift(days=3)))
|
||||
|
||||
# users = relationship("Users", back_populates="tokens", foreign_keys=[user_id])
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ class Users(CrudCollection, UserLoginModule, SelectAction):
|
|||
@classmethod
|
||||
def create_action(cls, create_user: InsertUsers):
|
||||
found_person = People.filter_one(
|
||||
People.uu_id==create_user.people_uu_id,
|
||||
People.uu_id == create_user.people_uu_id,
|
||||
*People.valid_record_args(People),
|
||||
).data
|
||||
if not found_person:
|
||||
|
|
|
|||
Loading…
Reference in New Issue