Esempio n. 1
0
    def resolve_resources(self, info):
        # Function to get all room resources
        page = self.page
        per_page = self.per_page
        unique = self.unique
        resource_labels = self.filter_data.get('resource_labels')
        active_resources = Resource.get_query(info).filter(
            ResourceModel.state == "active")
        if resource_labels:
            active_resources_query = room_resources_join_room(active_resources)
            for resourse_label in resource_labels.split(','):
                active_resources = active_resources_query.filter(
                    cast(RoomModel.room_labels, String)
                    .ilike(f'%{resourse_label.strip()}%'))

        if not page:
            if unique:
                return active_resources.distinct(ResourceModel.name).all()
            return active_resources.order_by(
                func.lower(ResourceModel.name)).all()
        page = validate_page(page)
        self.query_total = active_resources.count()
        result = active_resources.order_by(func.lower(
            ResourceModel.name)).limit(per_page).offset(page*per_page)
        if result.count() == 0:
            return GraphQLError("No more resources")
        return result
Esempio n. 2
0
 def resolve_users(self, info):
     page = self.page
     per_page = self.per_page
     query = User.get_query(info)
     if not page:
         return query.all()
     page = validate_page(page)
     self.query_total = query.count()
     result = query.limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No more resources")
     return result
Esempio n. 3
0
 def resolve_users(self, info):
     page = self.page
     per_page = self.per_page
     query = User.get_query(info)
     exact_query = user_filter(query, self.filter_data)
     if not page:
         return exact_query.all()
     page = validate_page(page)
     self.query_total = exact_query.count()
     result = exact_query.limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No users found")
     return result
Esempio n. 4
0
 def resolve_questions(self, info):
     page = self.page
     per_page = self.per_page
     query = Question.get_query(info)
     active_questions = query.filter(QuestionModel.state == "active")
     if not page:
         return active_questions.all()
     page = validate_page(page)
     self.query_total = active_questions.count()
     result = active_questions.limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No questions found")
     return result
Esempio n. 5
0
 def resolve_offices(self, info, **kwargs):
     page = self.page
     per_page = self.per_page
     query = Office.get_query(info)
     active_offices = query.filter(OfficeModel.state == "active")
     if not page:
         return active_offices.order_by(func.lower(OfficeModel.name)).all()
     page = validate_page(page)
     self.query_total = active_offices.count()
     result = active_offices.order_by(func.lower(
         OfficeModel.name)).limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No more offices")
     return result
Esempio n. 6
0
 def resolve_rooms(self, info, **kwargs):
     page = self.page
     per_page = self.per_page
     filter_data = self.filter_data
     query = Room.get_query(info)
     exact_query = room_filter(query, filter_data)
     if not page:
         return exact_query.all()
     page = validate_page(page)
     self.query_total = exact_query.count()
     result = exact_query.limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No more resources")
     return result
Esempio n. 7
0
 def resolve_users(self, info):
     page = self.page
     per_page = self.per_page
     query = User.get_query(info)
     active_user = query.filter(UserModel.state == "active")
     exact_query = user_filter(active_user, self.filter_data)
     if not page:
         return exact_query.order_by(func.lower(UserModel.email)).all()
     page = validate_page(page)
     self.query_total = exact_query.count()
     result = exact_query.order_by(func.lower(
         UserModel.name)).limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No users found")
     return result
Esempio n. 8
0
 def resolve_resources(self, info):
     page = self.page
     per_page = self.per_page
     unique = self.unique
     query = Resource.get_query(info)
     if not page:
         if unique:
             return query.distinct(ResourceModel.name).all()
         return query.all()
     page = validate_page(page)
     self.query_total = query.count()
     result = query.limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No more resources")
     return result
Esempio n. 9
0
 def resolve_rooms(self, info, **kwargs):
     page = self.page
     per_page = self.per_page
     filter_data = self.filter_data
     query = Room.get_query(info)
     exact_query = room_filter(query, filter_data)
     active_rooms = exact_query.filter(RoomModel.state == "active")
     if not page:
         return active_rooms.order_by(func.lower(RoomModel.name)).all()
     page = validate_page(page)
     self.query_total = active_rooms.count()
     result = active_rooms.order_by(func.lower(
         RoomModel.name)).limit(per_page).offset(page*per_page)
     if result.count() == 0:
         return GraphQLError("No more resources")
     return result
Esempio n. 10
0
 def resolve_resources(self, info):
     # Function to get all room resources
     page = self.page
     per_page = self.per_page
     unique = self.unique
     query = Resource.get_query(info)
     active_resources = query.filter(ResourceModel.state == "active")
     if not page:
         if unique:
             return active_resources.distinct(ResourceModel.name).all()
         return active_resources.order_by(func.lower(
             ResourceModel.name)).all()
     page = validate_page(page)
     self.query_total = active_resources.count()
     result = active_resources.order_by(func.lower(
         ResourceModel.name)).limit(per_page).offset(page * per_page)
     if result.count() == 0:
         return GraphQLError("No more resources")
     return result