From 820c12d6c1bddb06707ab72253ddc525ef7d4d33 Mon Sep 17 00:00:00 2001 From: Manus Date: Thu, 15 Jan 2026 13:01:17 -0500 Subject: [PATCH] =?UTF-8?q?Checkpoint:=20Modification=20de=20la=20proc?= =?UTF-8?q?=C3=A9dure=20testerRappel=20pour=20envoyer=20le=20rappel=20?= =?UTF-8?q?=C3=A0=20tous=20les=20inscrits=20confirm=C3=A9s=20:=20-=20Rempl?= =?UTF-8?q?acement=20de=20l'envoi=20au=20premier=20inscrit=20uniquement=20?= =?UTF-8?q?par=20un=20envoi=20=C3=A0=20tous=20les=20inscrits=20confirm?= =?UTF-8?q?=C3=A9s=20-=20Ajout=20d'un=20compteur=20de=20succ=C3=A8s=20et?= =?UTF-8?q?=20d'=C3=A9checs=20-=20Gestion=20des=20erreurs=20individuelles?= =?UTF-8?q?=20pour=20chaque=20envoi=20-=20Message=20de=20retour=20d=C3=A9t?= =?UTF-8?q?aill=C3=A9=20avec=20le=20nombre=20d'envois=20r=C3=A9ussis=20et?= =?UTF-8?q?=20=C3=A9chou=C3=A9s=20-=20D=C3=A9ploiement=20sur=20le=20VPS=20?= =?UTF-8?q?de=20production=20-=20Mise=20=C3=A0=20jour=20du=20fichier=20tod?= =?UTF-8?q?o.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/routers.ts | 86 ++++++++++++++++++++++++++++------------------- todo.md | 1 + 2 files changed, 52 insertions(+), 35 deletions(-) diff --git a/server/routers.ts b/server/routers.ts index 04d4dea..db259fb 100644 --- a/server/routers.ts +++ b/server/routers.ts @@ -1424,48 +1424,64 @@ export const appRouter = router({ throw new TRPCError({ code: 'BAD_REQUEST', message: 'Aucun apprenant inscrit confirmé pour cette séquence' }); } - // Envoyer le rappel de test au premier inscrit uniquement - const premierInscrit = inscritsConfirmes[0]; - const apprenant = premierInscrit.apprenant; - - if (!apprenant || !apprenant.email) { - throw new TRPCError({ code: 'BAD_REQUEST', message: 'Apprenant introuvable ou sans email' }); - } - + // Envoyer le rappel de test à l'administrateur connecté + // Envoyer le rappel de test à tous les inscrits confirmés const { sendRappelEmail } = await import('./emailService'); - try { - await sendRappelEmail({ - apprenantEmail: apprenant.email, - apprenantPrenom: apprenant.prenom, - apprenantNom: apprenant.nom, - apprenantFonction: apprenant.fonction || '', - formationNom: formation.nom, - sequenceNom: sequence.nom, - dates: dates.map((d: any) => ({ - dateDebut: d.dateDebut, - dateFin: d.dateFin, - ordre: d.ordre - })), - lieu: sequence.lieu || '', - formateur: formateurNom, - templateType: rappelAUtiliser.templateType, - attachmentUrl: rappelAUtiliser.urlFichier || undefined, - attachmentFilename: rappelAUtiliser.nomFichier || undefined, - attachmentMimeType: rappelAUtiliser.typeFichier || undefined, - }); + let nbEnvoyes = 0; + let nbEchecs = 0; + const erreurs: string[] = []; - return { - success: true, - message: `Rappel de test envoyé à ${apprenant.email}`, - destinataire: apprenant.email, - }; - } catch (error: any) { + for (const inscrit of inscritsConfirmes) { + const apprenant = inscrit.apprenant; + + if (!apprenant || !apprenant.email) { + nbEchecs++; + erreurs.push(`Apprenant ${apprenant?.nom || 'inconnu'}: email manquant`); + continue; + } + + try { + await sendRappelEmail({ + apprenantEmail: apprenant.email, + apprenantPrenom: apprenant.prenom, + apprenantNom: apprenant.nom, + apprenantFonction: apprenant.fonction || '', + formationNom: formation.nom, + sequenceNom: sequence.nom, + dates: dates.map((d: any) => ({ + dateDebut: d.dateDebut, + dateFin: d.dateFin, + ordre: d.ordre + })), + lieu: sequence.lieu || '', + formateur: formateurNom, + templateType: rappelAUtiliser.templateType, + attachmentUrl: rappelAUtiliser.urlFichier || undefined, + attachmentFilename: rappelAUtiliser.nomFichier || undefined, + attachmentMimeType: rappelAUtiliser.typeFichier || undefined, + }); + nbEnvoyes++; + } catch (error: any) { + nbEchecs++; + erreurs.push(`${apprenant.email}: ${error.message}`); + } + } + + if (nbEnvoyes === 0) { throw new TRPCError({ code: 'INTERNAL_SERVER_ERROR', - message: `Erreur lors de l'envoi: ${error.message}`, + message: `Aucun email envoyé. Erreurs: ${erreurs.join(', ')}`, }); } + + return { + success: true, + message: `Rappel de test envoyé à ${nbEnvoyes} apprenant(s)${nbEchecs > 0 ? ` (${nbEchecs} échec(s))` : ''}`, + nbEnvoyes, + nbEchecs, + erreurs: nbEchecs > 0 ? erreurs : undefined, + }; }), historique: adminProcedure diff --git a/todo.md b/todo.md index 42815ee..4c6e31e 100644 --- a/todo.md +++ b/todo.md @@ -820,3 +820,4 @@ - [x] Corriger l'erreur de validation du type de rappel dans la procédure testerRappel (typeRappel invalide) - [x] Corriger l'erreur "Cannot read properties of undefined (reading 'replace')" lors de l'envoi de test de rappel - [x] Améliorer le bouton "Tester le rappel" pour utiliser automatiquement le bon template configuré pour la séquence (au lieu de toujours envoyer rappel J-7) +- [x] Modifier la procédure testerRappel pour envoyer le rappel à tous les inscrits confirmés (au lieu du premier uniquement)