Skip to content

Commit

Permalink
Allow nil for update and delete mutation if the ID does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
ahukkanen committed Dec 4, 2023
1 parent 07db18a commit 3f35cd1
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/decidim/api/budget_mutation_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class BudgetMutationType < GraphQL::Schema::Object
argument :attributes, ProjectAttributes, required: true
end

field :update_project, Decidim::Budgets::ProjectType, null: false do
field :update_project, Decidim::Budgets::ProjectType, null: true do
description "A mutation to update a project within a budget."

argument :id, GraphQL::Types::ID, required: true
argument :attributes, ProjectAttributes, required: true
end

field :delete_project, Decidim::Budgets::ProjectType, null: false do
field :delete_project, Decidim::Budgets::ProjectType, null: true do
description "A mutation to delete a project within a budget."

argument :id, GraphQL::Types::ID, required: true
Expand Down Expand Up @@ -53,7 +53,9 @@ def create_project(attributes:)
end

def update_project(id:, attributes:)
project = object.projects.find(id)
project = object.projects.find_by(id: id)
return unless project

enforce_permission_to :update, :project, project: project

form = project_form_from(attributes)
Expand All @@ -74,7 +76,9 @@ def update_project(id:, attributes:)
end

def delete_project(id:)
project = object.projects.find(id)
project = object.projects.find_by(id: id)
return unless project

enforce_permission_to :destroy, :project, project: project

Decidim::Budgets::Admin::DestroyProject.call(project, current_user) do
Expand Down

0 comments on commit 3f35cd1

Please sign in to comment.