events updated

This commit is contained in:
berkay 2024-12-02 22:18:46 +03:00
parent a038a1b8ee
commit ac5a71f1a8
6 changed files with 154 additions and 25 deletions

View File

@ -14,7 +14,8 @@ from databases import (
AccountRecords, AccountRecords,
BuildIbans, BuildIbans,
) )
from databases.sql_models.building.build import Build from databases.sql_models.building.build import Build, BuildLivingSpace
from databases.sql_models.building.decision_book import BuildDecisionBookPayments
from databases.sql_models.others.enums import ApiEnumDropdown from databases.sql_models.others.enums import ApiEnumDropdown
@ -26,6 +27,7 @@ class AccountRecordsListEventMethods(MethodToEvent):
__event_keys__ = { __event_keys__ = {
"7192c2aa-5352-4e36-98b3-dafb7d036a3d": "account_records_list", "7192c2aa-5352-4e36-98b3-dafb7d036a3d": "account_records_list",
"208e6273-17ef-44f0-814a-8098f816b63a": "account_records_list_flt_res",
} }
@classmethod @classmethod
@ -46,15 +48,136 @@ class AccountRecordsListEventMethods(MethodToEvent):
AccountRecords.filter_attr = list_options AccountRecords.filter_attr = list_options
records = AccountRecords.filter_all() records = AccountRecords.filter_all()
return AlchemyJsonResponse( return AlchemyJsonResponse(
completed=True, message="Update Build record", result=records completed=True, message="List Build record", result=records
) )
@classmethod @classmethod
def account_records_list_flt_res_or_ten(cls): def account_records_list_flt_res(
""" cls,
FLT-RES | FLT-TEN | FLT-OWN aidatları görür list_options: ListOptions,
""" token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
return ):
if not isinstance(token_dict, OccupantTokenObject):
raise AccountRecords().raise_http_exception(
status_code="HTTP_404_NOT_FOUND",
error_case="UNAUTHORIZED",
message="Only Occupant can see this data",
data={},
)
return_list = []
living_space: BuildLivingSpace = BuildLivingSpace.filter_by_one(
id=token_dict.selected_occupant.living_space_id
).data
if not living_space:
raise AccountRecords().raise_http_exception(
status_code="HTTP_404_NOT_FOUND",
error_case="UNAUTHORIZED",
message="Living space not found",
data={},
)
if not list_options:
list_options = ListOptions()
main_filters = [
AccountRecords.living_space_id
== token_dict.selected_occupant.living_space_id,
BuildDecisionBookPayments.process_date
>= str(system_arrow.now().shift(months=-3).date()),
BuildDecisionBookPayments.process_date
< str(system_arrow.find_last_day_of_month(living_space.expiry_ends)),
BuildDecisionBookPayments.process_date
>= str(system_arrow.get(living_space.expiry_starts)),
BuildDecisionBookPayments.is_confirmed == True,
AccountRecords.active == True,
]
order_type = "desc"
if list_options.order_type:
order_type = "asc" if list_options.order_type[0] == "a" else "desc"
order_by_list = BuildDecisionBookPayments.process_date.desc()
if list_options.order_field:
if list_options.order_field == "process_date":
order_by_list = (
BuildDecisionBookPayments.process_date.asc()
if order_type == "asc"
else BuildDecisionBookPayments.process_date.desc()
)
if list_options.order_field == "bank_date":
order_by_list = (
AccountRecords.bank_date.desc()
if order_type == "asc"
else AccountRecords.bank_date.asc()
)
if list_options.order_field == "currency_value":
order_by_list = (
AccountRecords.currency_value.desc()
if order_type == "asc"
else AccountRecords.currency_value.asc()
)
if list_options.order_field == "process_comment":
order_by_list = (
AccountRecords.process_comment.desc()
if order_type == "asc"
else AccountRecords.process_comment.asc()
)
if list_options.order_field == "payment_amount":
order_by_list = (
BuildDecisionBookPayments.payment_amount.desc()
if order_type == "asc"
else BuildDecisionBookPayments.payment_amount.asc()
)
if list_options.query:
for key, value in list_options.query.items():
if key == "process_date":
main_filters.append(BuildDecisionBookPayments.process_date == value)
if key == "bank_date":
main_filters.append(AccountRecords.bank_date == value)
if key == "currency":
main_filters.append(BuildDecisionBookPayments.currency == value)
if key == "currency_value":
main_filters.append(AccountRecords.currency_value == value)
if key == "process_comment":
main_filters.append(AccountRecords.process_comment == value)
if key == "payment_amount":
main_filters.append(
BuildDecisionBookPayments.payment_amount == value
)
query = (
AccountRecords.session.query(
BuildDecisionBookPayments.process_date,
BuildDecisionBookPayments.payment_amount,
BuildDecisionBookPayments.currency,
AccountRecords.bank_date,
AccountRecords.currency_value,
AccountRecords.process_comment,
BuildDecisionBookPayments.uu_id,
)
.join(
AccountRecords,
AccountRecords.id == BuildDecisionBookPayments.account_records_id,
)
.filter(*main_filters)
).order_by(order_by_list)
query.limit(list_options.page_size or 5).offset(
(list_options.page or 1 - 1) * list_options.page_size or 5
)
for list_of_values in query.all() or []:
return_list.append(
{
"process_date": list_of_values[0],
"payment_amount": list_of_values[1],
"currency": list_of_values[2],
"bank_date": list_of_values[3],
"currency_value": list_of_values[4],
"process_comment": list_of_values[5],
}
)
return dict(completed=True, message="List Build record", result=return_list)
class AccountRecordsCreateEventMethods(MethodToEvent): class AccountRecordsCreateEventMethods(MethodToEvent):

View File

@ -38,7 +38,12 @@ from api_services import (
from api_configs import ApiStatic, Auth from api_configs import ApiStatic, Auth
from api_events.events.abstract_class import MethodToEvent, ActionsSchema from api_events.events.abstract_class import MethodToEvent, ActionsSchema
from api_objects.auth.token_objects import EmployeeTokenObject, OccupantTokenObject from api_objects import (
OccupantToken,
CompanyToken,
EmployeeTokenObject,
OccupantTokenObject,
)
from api_library.date_time_actions.date_functions import system_arrow from api_library.date_time_actions.date_functions import system_arrow
from databases.no_sql_models.login_handlers import load_user_with_erp_details from databases.no_sql_models.login_handlers import load_user_with_erp_details
@ -108,8 +113,6 @@ class AuthenticationSelectEventMethods(MethodToEvent):
data, data,
token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject], token_dict: typing.Union[EmployeeTokenObject, OccupantTokenObject],
): ):
from api_objects import OccupantToken, CompanyToken
if isinstance(token_dict, EmployeeTokenObject): if isinstance(token_dict, EmployeeTokenObject):
if data.company_uu_id not in token_dict.companies_uu_id_list: if data.company_uu_id not in token_dict.companies_uu_id_list:
return JSONResponse( return JSONResponse(
@ -436,9 +439,7 @@ class AuthenticationDisconnectUserEventMethods(MethodToEvent):
@classmethod @classmethod
def authentication_disconnect_user( def authentication_disconnect_user(
cls, cls, data: Logout, token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
data: Logout,
token_dict: Union[EmployeeTokenObject, OccupantTokenObject]
): ):
found_user = Users.filter_one(Users.uu_id == token_dict.user_uu_id).data found_user = Users.filter_one(Users.uu_id == token_dict.user_uu_id).data
if not found_user: if not found_user:
@ -586,8 +587,8 @@ class AuthenticationForgotPasswordEventMethods(MethodToEvent):
@classmethod @classmethod
def authentication_forgot_password( def authentication_forgot_password(
cls, cls,
request: Request, request: Request,
data: Forgot, data: Forgot,
): ):
found_user: Users = Users.check_user_exits( found_user: Users = Users.check_user_exits(
access_key=data.access_key, domain=data.domain access_key=data.access_key, domain=data.domain
@ -632,14 +633,16 @@ class AuthenticationDownloadAvatarEventMethods(MethodToEvent):
} }
@classmethod @classmethod
def authentication_download_avatar( def authentication_download_avatar(cls, data: Forgot):
cls, data: Forgot
):
if found_user := Users.check_user_exits( if found_user := Users.check_user_exits(
access_key=data.access_key, domain=data.domain access_key=data.access_key, domain=data.domain
): ):
expired_starts = str(system_arrow.now() - system_arrow.get(str(found_user.expiry_ends))) expired_starts = str(
expired_int = int(system_arrow.now() - system_arrow.get(str(found_user.expiry_ends)).days) system_arrow.now() - system_arrow.get(str(found_user.expiry_ends))
)
expired_int = int(
system_arrow.now() - system_arrow.get(str(found_user.expiry_ends)).days
)
return JSONResponse( return JSONResponse(
content={ content={
"completed": True, "completed": True,
@ -755,4 +758,4 @@ AuthenticationDownloadAvatarEventMethod = AuthenticationDownloadAvatarEventMetho
# is_login=False, # is_login=False,
# ) # )
# ) # )
# ) # )

View File

@ -53,6 +53,9 @@ from api_validations.core_response import AlchemyJsonResponse
class AuthenticationLoginEventMethods(MethodToEvent): class AuthenticationLoginEventMethods(MethodToEvent):
event_type = "LOGIN" event_type = "LOGIN"
event_description = "Login via domain and access key : [email] | [phone]"
event_category = "AUTHENTICATION"
__event_keys__ = { __event_keys__ = {
"e672846d-cc45-4d97-85d5-6f96747fac67": "authentication_login_with_domain_and_creds", "e672846d-cc45-4d97-85d5-6f96747fac67": "authentication_login_with_domain_and_creds",
} }
@ -102,7 +105,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
): ):
from api_objects import OccupantToken, CompanyToken from api_objects import OccupantToken, CompanyToken
if token_dict.user_type == 1: if isinstance(token_dict, EmployeeTokenObject):
if data.company_uu_id not in token_dict.companies_uu_id_list: if data.company_uu_id not in token_dict.companies_uu_id_list:
return JSONResponse( return JSONResponse(
content={ content={
@ -179,7 +182,7 @@ class AuthenticationSelectEventMethods(MethodToEvent):
}, },
status_code=status.HTTP_200_OK, status_code=status.HTTP_200_OK,
) )
elif token_dict.user_type == 2: elif isinstance(token_dict, OccupantTokenObject):
occupant_type = OccupantTypes.filter_by_one( occupant_type = OccupantTypes.filter_by_one(
system=True, uu_id=data.occupant_uu_id system=True, uu_id=data.occupant_uu_id
).data ).data

View File

@ -15,7 +15,6 @@ from databases import (
from api_validations.validations_request import ( from api_validations.validations_request import (
RegisterEvents2Employee, RegisterEvents2Employee,
RegisterEvents2Occupant, RegisterEvents2Occupant,
CreateEvents,
ListOptions, ListOptions,
) )

View File

@ -6,6 +6,7 @@ class BuildResident(AddEventFunctionality):
related_code = "FL-RES" related_code = "FL-RES"
events = [ events = [
{"function_code": "bdcba521-0116-441c-ace1-84c5b68c86c7"}, {"function_code": "bdcba521-0116-441c-ace1-84c5b68c86c7"},
{"function_code": "208e6273-17ef-44f0-814a-8098f816b63a"},
] ]
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):

View File

@ -3,7 +3,7 @@ from fastapi.routing import APIRouter
from api_services.redis.auth_actions.token import parse_token_object_to_dict from api_services.redis.auth_actions.token import parse_token_object_to_dict
from api_validations.validations_request import ( from api_validations.validations_request import (
CreateEvents, # CreateEvents,
ListOptions, ListOptions,
) )