add questions query

This commit is contained in:
João Geonizeli
2022-07-21 14:26:03 -03:00
parent 63c5fa52b8
commit 84a3815835
15 changed files with 177 additions and 14 deletions

View File

@@ -0,0 +1,32 @@
# frozen_string_literal: true
module Resolvers
class QuestionsQueryResolver
def initialize(initial_scope, context:, where:)
@initial_scope = initial_scope
@context = context
@where = where.to_h
end
def resolve
set_created_at_filter
unifeso_authorship = @where.delete(:unifeso_authorship)
scope = QuestionPolicy::Scope.new(@context[:current_user], @initial_scope).resolve
.where(@where)
.order(updated_at: :desc)
return scope if unifeso_authorship.nil?
unifeso_authorship ? scope.where(authorship: "UNIFESO") : scope.where.not(authorship: "UNIFESO")
end
private
def set_created_at_filter
create_date_range = @where.delete(:create_date)
@where[:created_at] = create_date_range[:start_at]..create_date_range[:end_at] if create_date_range
end
end
end