feat(graphql): returns dossier & message correction status
Co-authored-by: Paul Chavard <github@paul.chavard.net>
This commit is contained in:
parent
5998cfe31f
commit
873218222c
8 changed files with 100 additions and 4 deletions
|
@ -542,6 +542,23 @@ GeoJSON coordinates
|
|||
"""
|
||||
scalar Coordinates
|
||||
|
||||
type Correction {
|
||||
dateResolution: ISO8601DateTime
|
||||
reason: CorrectionReason!
|
||||
}
|
||||
|
||||
enum CorrectionReason {
|
||||
"""
|
||||
Le dossier est incomplet et nécessite d’être complété
|
||||
"""
|
||||
incomplete
|
||||
|
||||
"""
|
||||
Le dossier n’est pas valide et nécessite une correction
|
||||
"""
|
||||
incorrect
|
||||
}
|
||||
|
||||
"""
|
||||
Autogenerated input type of CreateDirectUpload
|
||||
"""
|
||||
|
@ -1301,6 +1318,11 @@ type Dossier {
|
|||
"""
|
||||
dateDepot: ISO8601DateTime!
|
||||
|
||||
"""
|
||||
Date de la dernière demande de correction qui n’a pas encore été traitée par l’usager.
|
||||
"""
|
||||
dateDerniereCorrectionEnAttente: ISO8601DateTime
|
||||
|
||||
"""
|
||||
Date de la dernière modification.
|
||||
"""
|
||||
|
@ -2826,6 +2848,7 @@ type Message {
|
|||
attachment: File @deprecated(reason: "Utilisez le champ `attachments` à la place.")
|
||||
attachments: [File!]!
|
||||
body: String!
|
||||
correction: Correction
|
||||
createdAt: ISO8601DateTime!
|
||||
email: String!
|
||||
id: ID!
|
||||
|
|
23
app/graphql/types/correction_type.rb
Normal file
23
app/graphql/types/correction_type.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
module Types
|
||||
class CorrectionType < Types::BaseObject
|
||||
class CorrectionReason < Types::BaseEnum
|
||||
# i18n-tasks-use t('dossier_correction.reasons.incorrect'), t('dossier_correction.reasons.incomplete')
|
||||
DossierCorrection.reasons.each do |symbol_name, string_name|
|
||||
value(string_name,
|
||||
I18n.t(symbol_name, scope: [:activerecord, :attributes, :dossier_correction, :reasons]),
|
||||
value: symbol_name)
|
||||
end
|
||||
end
|
||||
|
||||
field :reason, CorrectionReason, null: false
|
||||
field :date_resolution, GraphQL::Types::ISO8601DateTime, null: true
|
||||
|
||||
def date_resolution
|
||||
object.resolved_at
|
||||
end
|
||||
|
||||
def message
|
||||
object.commentaire
|
||||
end
|
||||
end
|
||||
end
|
|
@ -30,6 +30,8 @@ module Types
|
|||
field :date_suppression_par_administration, GraphQL::Types::ISO8601DateTime, "Date de la suppression par l’administration.", null: true, method: :hidden_by_administration_at
|
||||
field :date_expiration, GraphQL::Types::ISO8601DateTime, "Date d’expiration.", null: true
|
||||
|
||||
field :date_derniere_correction_en_attente, GraphQL::Types::ISO8601DateTime, "Date de la dernière demande de correction qui n’a pas encore été traitée par l’usager.", null: true
|
||||
|
||||
field :archived, Boolean, null: false
|
||||
|
||||
field :connection_usager, ConnectionUsager, null: false
|
||||
|
@ -75,6 +77,10 @@ module Types
|
|||
end
|
||||
end
|
||||
|
||||
def date_derniere_correction_en_attente
|
||||
Loaders::Association.for(object.class, :pending_correction).load(object).then { _1&.created_at }
|
||||
end
|
||||
|
||||
def connection_usager
|
||||
if object.user_deleted?
|
||||
:deleted
|
||||
|
|
|
@ -10,9 +10,14 @@ module Types
|
|||
field :attachments, [Types::File], null: false, extensions: [
|
||||
{ Extensions::Attachment => { attachment: :piece_jointe, as: :multiple } }
|
||||
]
|
||||
field :correction, CorrectionType, null: true
|
||||
|
||||
def body
|
||||
object.body.nil? ? "" : object.body
|
||||
end
|
||||
|
||||
def correction
|
||||
Loaders::Association.for(object.class, :dossier_correction).load(object)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,6 +5,7 @@ module DossierCorrectableConcern
|
|||
A_CORRIGER = 'a_corriger'
|
||||
has_many :corrections, class_name: 'DossierCorrection', dependent: :destroy
|
||||
has_many :pending_corrections, -> { DossierCorrection.pending }, class_name: 'DossierCorrection', inverse_of: :dossier
|
||||
has_one :pending_correction, -> { DossierCorrection.pending }, class_name: 'DossierCorrection', inverse_of: :dossier
|
||||
|
||||
scope :with_pending_corrections, -> { joins(:corrections).where(corrections: { resolved_at: nil }) }
|
||||
|
||||
|
@ -37,10 +38,6 @@ module DossierCorrectableConcern
|
|||
pending_corrections.exists?
|
||||
end
|
||||
|
||||
def pending_correction
|
||||
pending_corrections.first
|
||||
end
|
||||
|
||||
def resolve_pending_correction!
|
||||
pending_corrections.update!(resolved_at: Time.current)
|
||||
pending_corrections.reset
|
||||
|
|
7
config/locales/models/dossier_correction/en.yml
Normal file
7
config/locales/models/dossier_correction/en.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
en:
|
||||
activerecord:
|
||||
attributes:
|
||||
dossier_correction:
|
||||
reasons:
|
||||
incorrect: "The file is invalid and needs to be corrected"
|
||||
incomplete: "The file is incomplete and needs to be completed"
|
7
config/locales/models/dossier_correction/fr.yml
Normal file
7
config/locales/models/dossier_correction/fr.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
fr:
|
||||
activerecord:
|
||||
attributes:
|
||||
dossier_correction:
|
||||
reasons:
|
||||
incorrect: "Le dossier n’est pas valide et nécessite une correction"
|
||||
incomplete: "Le dossier est incomplet et nécessite d’être complété"
|
|
@ -241,6 +241,19 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
|
||||
it {
|
||||
expect(data[:dossier][:messages]).not_to be_nil
|
||||
expect(data[:dossier][:messages][0][:correction]).to be_nil
|
||||
}
|
||||
end
|
||||
|
||||
describe 'dossier with pending correction' do
|
||||
let(:dossier) { create(:dossier, :en_construction) }
|
||||
let!(:correction) { create(:dossier_correction, dossier:) }
|
||||
let(:query) { DOSSIER_WITH_CORRECTION_QUERY }
|
||||
let(:variables) { { number: dossier.id } }
|
||||
|
||||
it {
|
||||
expect(data[:dossier][:messages][0][:correction]).to eq({ reason: "incorrect", dateResolution: nil })
|
||||
expect(data[:dossier][:dateDerniereCorrectionEnAttente]).not_to be_nil
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -412,6 +425,21 @@ RSpec.describe Types::DossierType, type: :graphql do
|
|||
}
|
||||
GRAPHQL
|
||||
|
||||
DOSSIER_WITH_CORRECTION_QUERY = <<-GRAPHQL
|
||||
query($number: Int!) {
|
||||
dossier(number: $number) {
|
||||
dateDerniereCorrectionEnAttente
|
||||
messages {
|
||||
body
|
||||
correction {
|
||||
reason
|
||||
dateResolution
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GRAPHQL
|
||||
|
||||
DOSSIER_WITH_SELECTED_CHAMP_QUERY = <<-GRAPHQL
|
||||
query($number: Int!, $id: ID!) {
|
||||
dossier(number: $number) {
|
||||
|
|
Loading…
Reference in a new issue