demarches-normaliennes/app/graphql/mutations/groupe_instructeur_supprimer_instructeurs.rb
2023-03-08 11:59:58 +01:00

33 lines
1.3 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module Mutations
class GroupeInstructeurSupprimerInstructeurs < Mutations::BaseMutation
description "Supprimer des instructeurs dun groupe instructeur."
argument :groupe_instructeur_id, ID, "Groupe instructeur ID.", required: true, loads: Types::GroupeInstructeurType
argument :instructeurs, [Types::ProfileInput], "Instructeurs à supprimer.", required: true
field :groupe_instructeur, Types::GroupeInstructeurType, null: true
field :errors, [Types::ValidationErrorType], null: true
def resolve(groupe_instructeur:, instructeurs:)
ids, emails = partition_instructeurs_by(instructeurs)
instructeurs = groupe_instructeur.instructeurs.find_all_by_identifier(ids:, emails:)
if instructeurs.present?
instructeurs.each { groupe_instructeur.remove(_1) }
groupe_instructeur.reload
GroupeInstructeurMailer
.notify_group_when_instructeurs_removed(groupe_instructeur, instructeurs, current_administrateur.email)
.deliver_later
instructeurs.each do |instructeur|
GroupeInstructeurMailer
.notify_removed_instructeur(groupe_instructeur, instructeur, current_administrateur.email)
.deliver_later
end
end
{ groupe_instructeur: }
end
end
end