diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-12 15:06:26 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-12 15:06:26 +0000 |
commit | 69944ffb68788d190e81ff7e33db5dcb6c903184 (patch) | |
tree | 4112a1285f186c140749e8410a8a2788b6812500 /app/graphql/mutations/todos | |
parent | 1b7381e998ff4b33ec8f633766030082e95f10c8 (diff) | |
download | gitlab-ce-69944ffb68788d190e81ff7e33db5dcb6c903184.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/graphql/mutations/todos')
-rw-r--r-- | app/graphql/mutations/todos/base.rb | 17 | ||||
-rw-r--r-- | app/graphql/mutations/todos/mark_done.rb | 38 |
2 files changed, 55 insertions, 0 deletions
diff --git a/app/graphql/mutations/todos/base.rb b/app/graphql/mutations/todos/base.rb new file mode 100644 index 00000000000..b6c7b320be1 --- /dev/null +++ b/app/graphql/mutations/todos/base.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Mutations + module Todos + class Base < ::Mutations::BaseMutation + private + + def find_object(id:) + GitlabSchema.object_from_id(id) + end + + def to_global_id(id) + ::URI::GID.build(app: GlobalID.app, model_name: Todo.name, model_id: id, params: nil).to_s + end + end + end +end diff --git a/app/graphql/mutations/todos/mark_done.rb b/app/graphql/mutations/todos/mark_done.rb new file mode 100644 index 00000000000..5483708b5c6 --- /dev/null +++ b/app/graphql/mutations/todos/mark_done.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Mutations + module Todos + class MarkDone < ::Mutations::Todos::Base + graphql_name 'TodoMarkDone' + + authorize :update_todo + + argument :id, + GraphQL::ID_TYPE, + required: true, + description: 'The global id of the todo to mark as done' + + field :todo, Types::TodoType, + null: false, + description: 'The requested todo' + + # rubocop: disable CodeReuse/ActiveRecord + def resolve(id:) + todo = authorized_find!(id: id) + mark_done(Todo.where(id: todo.id)) unless todo.done? + + { + todo: todo.reset, + errors: errors_on_object(todo) + } + end + # rubocop: enable CodeReuse/ActiveRecord + + private + + def mark_done(todo) + TodoService.new.mark_todos_as_done(todo, current_user) + end + end + end +end |