feat(graphql): returns dossier & message correction status

Co-authored-by: Paul Chavard <github@paul.chavard.net>
This commit is contained in:
Colin Darie 2023-07-12 12:03:37 +02:00 committed by Paul Chavard
parent 5998cfe31f
commit 873218222c
8 changed files with 100 additions and 4 deletions

View file

@ -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 nest 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 na pas encore été traitée par lusager.
"""
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!

View 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

View file

@ -30,6 +30,8 @@ module Types
field :date_suppression_par_administration, GraphQL::Types::ISO8601DateTime, "Date de la suppression par ladministration.", null: true, method: :hidden_by_administration_at
field :date_expiration, GraphQL::Types::ISO8601DateTime, "Date dexpiration.", null: true
field :date_derniere_correction_en_attente, GraphQL::Types::ISO8601DateTime, "Date de la dernière demande de correction qui na pas encore été traitée par lusager.", 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

View file

@ -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

View file

@ -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

View 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"

View file

@ -0,0 +1,7 @@
fr:
activerecord:
attributes:
dossier_correction:
reasons:
incorrect: "Le dossier nest pas valide et nécessite une correction"
incomplete: "Le dossier est incomplet et nécessite dêtre complété"

View file

@ -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) {