from Schemas import ( Users, Events, Services, Service2Events, Applications, Application2Employee, Application2Occupant, Employees, Event2Employee, ) def init_service_to_event_matches_for_super_user(service_match: Services, employee_match: Employees, db_session=None) -> None: list_of_all_events = Events.filter_all(db=db_session).data Service2Events.filter_all(db=db_session).query.delete() Service2Events.save(db=db_session) for list_of_event_code in list_of_all_events: service_to_event_found = Service2Events.filter_one_system( Service2Events.event_id == list_of_event_code.id, Service2Events.service_id == service_match.id, db=db_session, ) if service_to_event_found.data: service_to_event_found.destroy(db=db_session) print( f"UUID: {service_to_event_found.uu_id} event is deleted from {service_match.service_description}" ) added_service = Service2Events.find_or_create( service_id=service_match.id, service_uu_id=str(service_match.uu_id), event_id=list_of_event_code.id, event_uu_id=str(list_of_event_code.uu_id), is_confirmed=True, active=True, db=db_session, ) if added_service.meta_data.created: added_service.save(db=db_session) print( f"UUID: {added_service.uu_id} event is saved to {service_match.service_description}" ) employee_added_service = Event2Employee.find_or_create( event_service_id=service_match.id, event_service_uu_id=str(service_match.uu_id), employee_id=employee_match.id, employee_uu_id=str(employee_match.uu_id), is_confirmed=True, db=db_session, ) if employee_added_service.meta_data.created: employee_added_service.save(db=db_session) print( f"UUID: {employee_added_service.uu_id} event is saved to employee {employee_match.uu_id}" )