Skip to content

Commit

Permalink
R2-2919 - UAT: Cannot edit information for a document already added t…
Browse files Browse the repository at this point in the history
…o a case

Add endpoint to update attachemnts
  • Loading branch information
dhernandez-quoin committed Jul 5, 2024
1 parent 3a499dc commit 3117df7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/controllers/api/v2/attachments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def create
updates_for_record(@record)
end

def update
@attachment = Attachment.find(attachment_update_params[:id])
@attachment.assign_attributes(attachment_update_params.except(:id))
@attachment.save!
updates_for_record(@record)
end

def destroy
@attachment = Attachment.find(params[:id])
authorize! :destroy, @attachment
Expand Down Expand Up @@ -38,4 +45,12 @@ def attachment_params
@attachment_params[:record] = @record
@attachment_params
end

def attachment_update_params
return @attachment_update_params if @attachment_update_params

@attachment_update_params = params.require(:data).permit(:id, :description, :is_current, :comments).to_h
@attachment_update_params[:record] = @record
@attachment_update_params
end
end
8 changes: 8 additions & 0 deletions app/views/api/v2/attachments/update.json.jbuilder
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

# Copyright (c) 2014 - 2023 UNICEF. All rights reserved.

json.data do
json.partial! 'api/v2/attachments/attachment',
attachment: @attachment, updates_for_record: @updated_field_names
end
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
resources :transfers, only: %i[index create update]
resources :transfer_requests, only: %i[index create update]
resources :transitions, only: [:index]
resources :attachments, only: %i[create destroy]
resources :attachments, only: %i[create destroy update]
resources :approvals, only: [:update]
resources :potential_matches, only: [:index]
resources :webhook_syncs, as: :sync, path: :sync, only: [:create]
Expand Down

0 comments on commit 3117df7

Please sign in to comment.