2024-04-15 15:06:05 +02:00
|
|
|
class Champs::PieceJustificativeController < Champs::ChampController
|
2022-11-09 12:33:20 +01:00
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.turbo_stream
|
|
|
|
format.html { redirect_back(fallback_location: root_url) }
|
|
|
|
end
|
|
|
|
end
|
2020-03-30 15:34:56 +02:00
|
|
|
|
|
|
|
def update
|
2022-12-22 20:55:15 +01:00
|
|
|
if attach_piece_justificative
|
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
|
|
|
|
2022-12-01 17:57:53 +01:00
|
|
|
def template
|
|
|
|
redirect_to @champ.type_de_champ.piece_justificative_template.blob
|
|
|
|
end
|
|
|
|
|
2021-11-16 15:51:49 +01:00
|
|
|
private
|
|
|
|
|
2022-11-09 12:33:20 +01:00
|
|
|
def attach_piece_justificative
|
2022-12-13 15:22:18 +01:00
|
|
|
save_succeed = nil
|
|
|
|
|
|
|
|
ActiveStorage::Attachment.transaction do
|
|
|
|
@champ.piece_justificative_file.attach(params[:blob_signed_id])
|
|
|
|
save_succeed = @champ.save
|
|
|
|
end
|
|
|
|
|
2022-01-05 18:02:43 +01:00
|
|
|
@champ.dossier.update(last_champ_updated_at: Time.zone.now.utc) if save_succeed
|
2022-12-13 15:22:18 +01:00
|
|
|
|
2022-01-05 18:02:43 +01:00
|
|
|
save_succeed
|
2021-11-16 15:51:49 +01:00
|
|
|
end
|
2020-03-30 15:34:56 +02:00
|
|
|
end
|