2019-10-17 11:06:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Resolvers
|
|
|
|
class TodoResolver < BaseResolver
|
2020-11-09 19:08:52 -05:00
|
|
|
type Types::TodoType.connection_type, null: true
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-08-03 11:09:44 -04:00
|
|
|
alias_method :target, :object
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
argument :action, [Types::TodoActionEnum],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The action to be filtered.'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
argument :author_id, [GraphQL::ID_TYPE],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The ID of an author.'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
argument :project_id, [GraphQL::ID_TYPE],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The ID of a project.'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
argument :group_id, [GraphQL::ID_TYPE],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The ID of a group.'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
argument :state, [Types::TodoStateEnum],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The state of the todo.'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
argument :type, [Types::TodoTargetEnum],
|
|
|
|
required: false,
|
2021-01-11 19:10:42 -05:00
|
|
|
description: 'The type of the todo.'
|
2019-10-17 11:06:17 -04:00
|
|
|
|
|
|
|
def resolve(**args)
|
2020-08-03 11:09:44 -04:00
|
|
|
return Todo.none unless current_user.present? && target.present?
|
|
|
|
return Todo.none if target.is_a?(User) && target != current_user
|
2019-10-17 11:06:17 -04:00
|
|
|
|
2020-08-03 11:09:44 -04:00
|
|
|
TodosFinder.new(current_user, todo_finder_params(args)).execute
|
2019-10-17 11:06:17 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def todo_finder_params(args)
|
|
|
|
{
|
2019-11-19 16:06:22 -05:00
|
|
|
state: args[:state],
|
|
|
|
type: args[:type],
|
|
|
|
group_id: args[:group_id],
|
|
|
|
author_id: args[:author_id],
|
|
|
|
action_id: args[:action],
|
|
|
|
project_id: args[:project_id]
|
2020-08-03 11:09:44 -04:00
|
|
|
}.merge(target_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def target_params
|
|
|
|
return {} unless TodosFinder::TODO_TYPES.include?(target.class.name)
|
|
|
|
|
|
|
|
{
|
|
|
|
type: target.class.name,
|
|
|
|
target_id: target.id
|
2019-10-17 11:06:17 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|