2020-03-30 15:34:56 +02:00
|
|
|
class Champs::PieceJustificativeController < ApplicationController
|
|
|
|
before_action :authenticate_logged_user!
|
|
|
|
|
|
|
|
def update
|
2021-11-16 15:51:49 +01:00
|
|
|
if attach_piece_justificative_or_retry
|
2020-03-30 15:34:56 +02:00
|
|
|
render :show
|
|
|
|
else
|
2021-11-16 15:51:49 +01:00
|
|
|
render json: { errors: @champ.errors.full_messages }, status: 422
|
2020-03-30 15:34:56 +02:00
|
|
|
end
|
|
|
|
end
|
2021-11-16 15:51:49 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def attach_piece_justificative
|
|
|
|
@champ = policy_scope(Champ).find(params[:champ_id])
|
|
|
|
@champ.piece_justificative_file.attach(params[:blob_signed_id])
|
2022-01-05 18:02:43 +01:00
|
|
|
save_succeed = @champ.save
|
|
|
|
@champ.dossier.update(last_champ_updated_at: Time.zone.now.utc) if save_succeed
|
|
|
|
save_succeed
|
2021-11-16 15:51:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def attach_piece_justificative_or_retry
|
|
|
|
attach_piece_justificative
|
|
|
|
rescue ActiveRecord::StaleObjectError
|
|
|
|
attach_piece_justificative
|
|
|
|
end
|
2020-03-30 15:34:56 +02:00
|
|
|
end
|