Skip to content

Commit

Permalink
Merge pull request #9348 from tchak/feat-submit-en-construction
Browse files Browse the repository at this point in the history
refactor: move submit en_construction logic to the model
  • Loading branch information
tchak authored Jul 24, 2023
2 parents a492d7f + 93d6bda commit 1dfb381
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 2 additions & 6 deletions app/controllers/users/dossiers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,10 @@ def submit_en_construction
errors = submit_dossier_and_compute_errors

if errors.blank?
pending_correction_confirm = cast_bool(params.dig(:dossier, :pending_correction_confirm))
editing_fork_origin = @dossier.editing_fork_origin
editing_fork_origin.merge_fork(@dossier)
RoutingEngine.compute(editing_fork_origin)

if cast_bool(params.dig(:dossier, :pending_correction_confirm))
editing_fork_origin.resolve_pending_correction!
editing_fork_origin.process_sva_svr!
end
editing_fork_origin.submit_en_construction!(pending_correction_confirm:)

redirect_to dossier_path(editing_fork_origin)
else
Expand Down
16 changes: 16 additions & 0 deletions app/models/dossier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def passer_en_construction(instructeur: nil, processed_at: Time.zone.now)
processed_at: processed_at)
end

def submit_en_construction(processed_at: Time.zone.now)
build(state: Dossier.states.fetch(:en_construction), processed_at:)
end

def passer_en_instruction(instructeur: nil, processed_at: Time.zone.now)
build(state: Dossier.states.fetch(:en_instruction),
instructeur_email: instructeur&.email,
Expand Down Expand Up @@ -908,6 +912,18 @@ def after_passer_en_construction
RoutingEngine.compute(self)
end

def submit_en_construction!(pending_correction_confirm: false)
self.traitements.submit_en_construction
save!

RoutingEngine.compute(self)

if pending_correction_confirm
resolve_pending_correction!
process_sva_svr!
end
end

def after_passer_en_instruction(h)
instructeur = h[:instructeur]
disable_notification = h.fetch(:disable_notification, false)
Expand Down

0 comments on commit 1dfb381

Please sign in to comment.