Merge pull request #6645 from tchak/fix-attach-piece-justificative

fix(champs): attach piece justificative
This commit is contained in:
Paul Chavard 2021-11-16 18:52:35 +03:00 committed by GitHub
commit 3b82ea0632
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,14 +2,24 @@ class Champs::PieceJustificativeController < ApplicationController
before_action :authenticate_logged_user!
def update
@champ = policy_scope(Champ).find(params[:champ_id])
@champ.piece_justificative_file.attach(params[:blob_signed_id])
if @champ.save
if attach_piece_justificative_or_retry
render :show
else
errors = @champ.errors.full_messages
render :json => { errors: errors }, :status => 422
render json: { errors: @champ.errors.full_messages }, status: 422
end
end
private
def attach_piece_justificative
@champ = policy_scope(Champ).find(params[:champ_id])
@champ.piece_justificative_file.attach(params[:blob_signed_id])
@champ.save
end
def attach_piece_justificative_or_retry
attach_piece_justificative
rescue ActiveRecord::StaleObjectError
attach_piece_justificative
end
end