feat(exports): add statut and procedure_presentation to exports
This commit is contained in:
parent
19d07a01d5
commit
be1a2f916d
5 changed files with 39 additions and 10 deletions
|
@ -5,9 +5,11 @@
|
|||
# id :bigint not null, primary key
|
||||
# format :string not null
|
||||
# key :text not null
|
||||
# statut :string default("tous")
|
||||
# time_span_type :string default("everything"), not null
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# procedure_presentation_id :bigint
|
||||
#
|
||||
class Export < ApplicationRecord
|
||||
MAX_DUREE_CONSERVATION_EXPORT = 3.hours
|
||||
|
@ -23,7 +25,18 @@ class Export < ApplicationRecord
|
|||
monthly: 'monthly'
|
||||
}
|
||||
|
||||
enum statut: {
|
||||
'a-suivre': 'a-suivre',
|
||||
suivis: 'suivis',
|
||||
traites: 'traites',
|
||||
tous: 'tous',
|
||||
supprimes_recemment: 'supprimes_recemment',
|
||||
archives: 'archives',
|
||||
expirant: 'expirant'
|
||||
}
|
||||
|
||||
has_and_belongs_to_many :groupe_instructeurs
|
||||
belongs_to :procedure_presentation, optional: true
|
||||
|
||||
has_one_attached :file
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@ class ProcedurePresentation < ApplicationRecord
|
|||
FILTERS_VALUE_MAX_LENGTH = 100
|
||||
|
||||
belongs_to :assign_to, optional: false
|
||||
has_many :exports, dependent: :destroy
|
||||
|
||||
delegate :procedure, :instructeur, to: :assign_to
|
||||
|
||||
validate :check_allowed_displayed_fields
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
class AddProcedurePresentationAndStateToExports < ActiveRecord::Migration[6.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_reference :exports, :procedure_presentation, null: true, index: { algorithm: :concurrently }
|
||||
add_column :exports, :statut, :string, default: 'tous'
|
||||
remove_index :exports, [:format, :time_span_type, :key]
|
||||
add_index :exports, [:format, :time_span_type, :statut, :key], unique: true, algorithm: :concurrently
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2022_04_05_100354) do
|
||||
ActiveRecord::Schema.define(version: 2022_04_05_110354) do
|
||||
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
@ -431,9 +431,12 @@ ActiveRecord::Schema.define(version: 2022_04_05_100354) do
|
|||
t.datetime "created_at", null: false
|
||||
t.string "format", null: false
|
||||
t.text "key", null: false
|
||||
t.bigint "procedure_presentation_id"
|
||||
t.string "statut", default: "tous"
|
||||
t.string "time_span_type", default: "everything", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["format", "time_span_type", "key"], name: "index_exports_on_format_and_time_span_type_and_key", unique: true
|
||||
t.index ["format", "time_span_type", "statut", "key"], name: "index_exports_on_format_and_time_span_type_and_statut_and_key", unique: true
|
||||
t.index ["procedure_presentation_id"], name: "index_exports_on_procedure_presentation_id"
|
||||
end
|
||||
|
||||
create_table "exports_groupe_instructeurs", force: :cascade do |t|
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
FactoryBot.define do
|
||||
factory :export do
|
||||
format { :csv }
|
||||
format { Export.formats.fetch(:csv) }
|
||||
statut { Export.statuts.fetch(:tous) }
|
||||
time_span_type { Export.time_span_types.fetch(:everything) }
|
||||
groupe_instructeurs { [association(:groupe_instructeur)] }
|
||||
|
||||
after(:build) do |export, _evaluator|
|
||||
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id))
|
||||
export.key = Export.generate_cache_key(export.groupe_instructeurs.map(&:id), export.procedure_presentation&.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue