2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Interface to expose todos for the current_user on the `object`
|
|
|
|
module Types
|
|
|
|
module CurrentUserTodos
|
|
|
|
include BaseInterface
|
|
|
|
|
|
|
|
field_class Types::BaseField
|
|
|
|
|
|
|
|
field :current_user_todos, Types::TodoType.connection_type,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'To-do items for the current user.',
|
2020-11-24 15:15:51 +05:30
|
|
|
null: false do
|
|
|
|
argument :state, Types::TodoStateEnum,
|
2021-03-11 19:13:27 +05:30
|
|
|
description: 'State of the to-do items.',
|
2020-11-24 15:15:51 +05:30
|
|
|
required: false
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_user_todos(state: nil)
|
2021-04-17 20:07:23 +05:30
|
|
|
state ||= %i[done pending] # TodosFinder treats a `nil` state param as `pending`
|
|
|
|
klass = unpresented.class
|
2020-11-24 15:15:51 +05:30
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
TodosFinder.new(current_user, state: state, type: klass.name, target_id: object.id).execute
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|