diff --git a/app/controllers/api/v1/dossiers_controller.rb b/app/controllers/api/v1/dossiers_controller.rb index 40cbcc1fa..5eb8eaadd 100644 --- a/app/controllers/api/v1/dossiers_controller.rb +++ b/app/controllers/api/v1/dossiers_controller.rb @@ -45,7 +45,7 @@ class API::V1::DossiersController < APIController render json: {}, status: :unauthorized end - @dossiers = @procedure.dossiers.state_not_brouillon + @dossiers = @procedure.dossiers.state_not_brouillon.order_for_api rescue ActiveRecord::RecordNotFound render json: {}, status: :not_found diff --git a/app/models/dossier.rb b/app/models/dossier.rb index abcfd983f..0bcb8669a 100644 --- a/app/models/dossier.rb +++ b/app/models/dossier.rb @@ -51,6 +51,7 @@ class Dossier < ApplicationRecord scope :not_archived, -> { where(archived: false) } scope :order_by_updated_at, -> (order = :desc) { order(updated_at: order) } + scope :order_for_api, -> (order = :asc) { order(en_construction_at: order, created_at: order, id: order) } scope :all_state, -> { not_archived.state_not_brouillon } scope :en_construction, -> { not_archived.state_en_construction }