join tested auth service login/select completed

This commit is contained in:
2025-05-13 13:19:01 +03:00
parent 1d4f00e8b2
commit cd62d96158
34 changed files with 1360 additions and 231 deletions

View File

@@ -316,27 +316,16 @@ class Event2Employee(CrudCollection):
@classmethod
def get_event_codes(cls, employee_id: int, db) -> dict[str:str]:
employee_events = cls.filter_all(
cls.employee_id == employee_id,
db=db,
).data
cls.set_session(db)
Service2Events.set_session(db)
Events.set_session(db)
Event2EmployeeExtra.set_session(db)
employee_events = cls.query.filter(cls.employee_id == employee_id).all()
service_ids = list(set([event.event_service_id for event in employee_events]))
active_event_ids = Service2Events.filter_all(
Service2Events.service_id.in_(service_ids),
db=db,
).data
active_events = Events.filter_all(
Events.id.in_([event.event_id for event in active_event_ids]),
db=db,
).data
if extra_events := Event2EmployeeExtra.filter_all(
Event2EmployeeExtra.employee_id == employee_id,
db=db,
).data:
events_extra = Events.filter_all(
Events.id.in_([event.event_id for event in extra_events]),
db=db,
).data
active_event_ids = Service2Events.query.filter(Service2Events.service_id.in_(service_ids)).all()
active_events = Events.query.filter(Events.id.in_([event.event_id for event in active_event_ids])).all()
if extra_events := Event2EmployeeExtra.query.filter(Event2EmployeeExtra.employee_id == employee_id).all():
events_extra = Events.query.filter(Events.id.in_([event.event_id for event in extra_events]),).all()
active_events.extend(events_extra)
events_dict = {}
for event in active_events:
@@ -382,27 +371,15 @@ class Event2Occupant(CrudCollection):
@classmethod
def get_event_codes(cls, build_living_space_id: int, db) -> dict[str:str]:
occupant_events = cls.filter_all(
cls.build_living_space_id == build_living_space_id,
db=db,
).data
cls.set_session(db)
Service2Events.set_session(db)
Events.set_session(db)
occupant_events = cls.query.filter(cls.build_living_space_id == build_living_space_id).all()
service_ids = list(set([event.event_service_id for event in occupant_events]))
active_event_ids = Service2Events.filter_all_system(
Service2Events.service_id.in_(service_ids),
db=db,
).data
active_events = Events.filter_all(
Events.id.in_([event.event_id for event in active_event_ids]),
db=db,
).data
if extra_events := Event2OccupantExtra.filter_all(
Event2OccupantExtra.build_living_space_id == build_living_space_id,
db=db,
).data:
events_extra = Events.filter_all(
Events.id.in_([event.event_id for event in extra_events]),
db=db,
).data
active_event_ids = Service2Events.query.filter(Service2Events.service_id.in_(service_ids)).all()
active_events = Events.query.filter(Events.id.in_([event.event_id for event in active_event_ids])).all()
if extra_events := Event2OccupantExtra.query.filter(Event2OccupantExtra.build_living_space_id == build_living_space_id).all():
events_extra = Events.query.filter(Events.id.in_([event.event_id for event in extra_events])).all()
active_events.extend(events_extra)
events_dict = {}
for event in active_events:
@@ -428,31 +405,16 @@ class Application2Employee(CrudCollection):
@classmethod
def get_application_codes(cls, employee_id: int, db) -> list[int]:
employee_services = cls.filter_all(
cls.employee_id == employee_id,
db=db,
).data
cls.set_session(db)
Service2Application.set_session(db)
Applications.set_session(db)
Application2EmployeeExtra.set_session(db)
employee_services = cls.query.filter(cls.employee_id == employee_id).all()
service_ids = [service.service_id for service in employee_services]
active_applications = Service2Application.filter_all(
Service2Application.service_id.in_(service_ids),
db=db,
).data
applications = Applications.filter_all(
Applications.id.in_(
[application.application_id for application in active_applications]
),
db=db,
).data
if extra_applications := Application2EmployeeExtra.filter_all(
Application2EmployeeExtra.employee_id == employee_id,
db=db,
).data:
applications_extra = Applications.filter_all(
Applications.id.in_(
[application.application_id for application in extra_applications]
),
db=db,
).data
active_applications = Service2Application.query.filter(Service2Application.service_id.in_(service_ids)).all()
applications = Applications.query.filter(Applications.id.in_([application.application_id for application in active_applications])).all()
if extra_applications := Application2EmployeeExtra.query.filter(Application2EmployeeExtra.employee_id == employee_id).all():
applications_extra = Applications.query.filter(Applications.id.in_([application.application_id for application in extra_applications])).all()
applications.extend(applications_extra)
applications_dict = {}
for application in applications:
@@ -492,33 +454,25 @@ class Application2Occupant(CrudCollection):
@classmethod
def get_application_codes(cls, build_living_space_id: int, db) -> list[int]:
occupant_services = cls.filter_all(
cls.build_living_space_id == build_living_space_id,
db=db,
).data
cls.set_session(db)
Service2Application.set_session(db)
Applications.set_session(db)
Application2OccupantExtra.set_session(db)
occupant_services = cls.query.filter(cls.build_living_space_id == build_living_space_id).all()
service_ids = [service.service_id for service in occupant_services]
active_applications = Service2Application.filter_all(
Service2Application.service_id.in_(service_ids),
db=db,
).data
applications = Applications.filter_all(
Applications.id.in_(
[application.application_id for application in active_applications]
),
db=db,
).data
if extra_applications := Application2OccupantExtra.filter_all(
Application2OccupantExtra.build_living_space_id == build_living_space_id,
db=db,
).data:
applications_extra = Applications.filter_all(
Applications.id.in_(
[application.application_id for application in extra_applications]
),
db=db,
).data
active_applications = Service2Application.query.filter(Service2Application.service_id.in_(service_ids)).all()
applications = Applications.query.filter(Applications.id.in_([application.application_id for application in active_applications])).all()
if extra_applications := Application2OccupantExtra.query.filter(Application2OccupantExtra.build_living_space_id == build_living_space_id).all():
applications_extra = Applications.query.filter(Applications.id.in_([application.application_id for application in extra_applications])).all()
applications.extend(applications_extra)
applications_dict = {}
for application in applications:
if not application.site_url in applications_dict:
applications_dict[str(application.site_url)] = str(application.application_code)
else:
ValueError("Duplicate application code found for single endpoint")
applications.extend(applications_extra)
applications_dict = {}
for application in applications:
if not application.site_url in applications_dict:
applications_dict[str(application.site_url)] = str(application.application_code)