2022-07-21 14:54:14 +02:00
|
|
|
|
module Mutations
|
|
|
|
|
class DossierModifierAnnotationAjouterLigne < Mutations::BaseMutation
|
|
|
|
|
argument :dossier_id, ID, "Dossier ID", required: true, loads: Types::DossierType
|
|
|
|
|
argument :instructeur_id, ID, "Instructeur qui demande la modification.", required: true, loads: Types::ProfileType
|
|
|
|
|
argument :annotation_id, ID, "Annotation ID", required: true
|
|
|
|
|
|
|
|
|
|
field :annotation, Types::Champs::RepetitionChampType, null: true
|
|
|
|
|
field :errors, [Types::ValidationErrorType], null: true
|
|
|
|
|
|
|
|
|
|
def resolve(dossier:, annotation_id:, instructeur:)
|
|
|
|
|
annotation = find_annotation(dossier, annotation_id)
|
|
|
|
|
|
|
|
|
|
if annotation.nil?
|
|
|
|
|
return { errors: ["L’annotation \"#{annotation_id}\" n’existe pas"] }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
annotation.add_row(dossier.revision)
|
|
|
|
|
|
2022-12-07 13:21:55 +01:00
|
|
|
|
{ annotation:, errors: nil }
|
2022-07-21 14:54:14 +02:00
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def authorized?(dossier:, instructeur:, **args)
|
|
|
|
|
dossier_authorized_for?(dossier, instructeur)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def find_annotation(dossier, annotation_id)
|
2024-03-27 11:35:42 +01:00
|
|
|
|
stable_id, _row_id = Champ.decode_typed_id(annotation_id)
|
|
|
|
|
type_de_champ = dossier.revision.types_de_champ
|
|
|
|
|
.private_only
|
|
|
|
|
.find_by(type_champ: TypeDeChamp.type_champs.fetch(:repetition), stable_id:)
|
2022-07-21 14:54:14 +02:00
|
|
|
|
|
2024-03-27 11:35:42 +01:00
|
|
|
|
return nil if type_de_champ.nil?
|
|
|
|
|
dossier.project_champ(type_de_champ, nil)
|
2022-07-21 14:54:14 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|