def mutate(self, info, **kwargs): validate_empty_fields(**kwargs) verify_location_id(kwargs) query = RoomModel.query validate_room_labels(**kwargs, query=query) validate_structure_id(**kwargs) admin_roles.create_rooms_update_delete_location(kwargs) query = Room.get_query(info) active_rooms = query.filter(RoomModel.state == "active") query_result = [room for room in active_rooms if room.calendar_id == kwargs.get('calendar_id')] if query_result: ErrorHandler.check_conflict( self, kwargs['calendar_id'], 'CalenderId') exact_query = room_join_location(active_rooms) result = exact_query.filter( RoomModel.name == kwargs.get('name'), RoomModel.state == "active", RoomModel.location_id == kwargs.get('location_id') ) if result.count(): ErrorHandler.check_conflict(self, kwargs['name'], 'Room') room_tags = [] if kwargs.get('room_tags'): room_tags = kwargs.pop('room_tags') room = RoomModel(**kwargs) save_room_tags(room, room_tags) requests.get(url=Config.MRM_PUSH_URL + "/add_room", params={"calendar_id": room.calendar_id, "firebase_token": room.firebase_token}) return CreateRoom(room=room)
def mutate(self, info, **kwargs): validate_empty_fields(**kwargs) verify_location_id(kwargs) admin_roles.create_rooms_update_delete_location(kwargs) query = Room.get_query(info) active_rooms = query.filter(RoomModel.state == "active") query_result = [room for room in active_rooms if room.calendar_id == kwargs.get('calendar_id')] if query_result: ErrorHandler.check_conflict( self, kwargs['calendar_id'], 'CalenderId') exact_query = room_join_location(active_rooms) result = exact_query.filter( RoomModel.name == kwargs.get('name'), RoomModel.state == "active", RoomModel.location_id == kwargs.get('location_id') ) if result.count(): ErrorHandler.check_conflict(self, kwargs['name'], 'Room') room_tags = [] if kwargs.get('room_tags'): room_tags = kwargs.pop('room_tags') room = RoomModel(**kwargs) save_room_tags(room, room_tags) return CreateRoom(room=room)
def resolve_get_office_by_name(self, info, name): # Returns a specific office using its name query = Office.get_query(info) active_offices = query.filter(OfficeModel.state == "active") check_office = active_offices.filter(OfficeModel.name == name).first() if not check_office: raise GraphQLError("Office Not found") if name == "Epic tower": exact_query = lagos_office_join_location(active_offices) result = exact_query.filter(OfficeModel.name == name) return result.all() else: exact_query = room_join_location(active_offices) result = exact_query.filter(OfficeModel.name == name) return result.all()
def get_calendar_id_name(self, query): """ Get all room(name, calendar_id) in a location :params """ location_id = admin_roles.admin_location_for_analytics_view() exact_query = room_join_location(query) rooms_in_locations = exact_query.filter( LocationModel.id == location_id) if not rooms_in_locations.all(): raise GraphQLError("No rooms in this location") result = [{ 'name': room.name, 'calendar_id': room.calendar_id } for room in rooms_in_locations.all()] return result
def resolve_get_office_by_name(self, info, name): query = Office.get_query(info) check_office = query.filter(OfficeModel.name == name).first() if not check_office: raise GraphQLError("Office Not found") if name == "Epic tower": exact_query = lagos_office_join_location(query) result = exact_query.filter(OfficeModel.name == name) return result.all() else: exact_query = room_join_location(query) result = exact_query.filter(OfficeModel.name == name) return result.all()
def get_room_details(self, query): """ Get all room(name, calendar_id, room_id) in a location :params """ location_id = admin_roles.user_location_for_analytics_view() exact_query = room_join_location(query) rooms_in_locations = exact_query.filter( LocationModel.id == location_id) if not rooms_in_locations.all(): if 'analytics' in request.url: raise JsonError(Message='No rooms in this location') else: raise GraphQLError("No rooms in this location") result = [{ 'name': room.name, 'room_id': room.id, 'calendar_id': room.calendar_id } for room in rooms_in_locations.all()] return result
def resolve_get_rooms_in_a_location(self, info, location_id): query = Room.get_query(info) exact_query = room_join_location(query) result = exact_query.filter(LocationModel.id == location_id) return result.all()
def resolve_get_rooms_in_a_location(self, info, location_id): query = Room.get_query(info) active_rooms = query.filter(RoomModel.state == "active") exact_query = room_join_location(active_rooms) result = exact_query.filter(LocationModel.id == location_id) return result.all()
def resolve_get_rooms_in_a_block(self, info, block_id): query = Room.get_query(info) new_query = room_join_location(query) result = new_query.filter(BlockModel.id == block_id) return result