From 7590c95f06fb008a780d5980e4ec677631afa765 Mon Sep 17 00:00:00 2001 From: Julien Martin Date: Fri, 17 Apr 2026 18:37:47 +0200 Subject: [PATCH] refactor(mail): #28 un seul template email parent (principal + co-parent) Made-with: Cursor --- backend/src/modules/mail/mail.service.spec.ts | 3 +-- backend/src/modules/mail/mail.service.ts | 8 +++----- .../account-validated-parent-coparent.hbs | 14 -------------- ...-primary.hbs => account-validated-parent.hbs} | 4 ++-- backend/src/routes/user/user.service.ts | 16 ++-------------- docs/23_LISTE-TICKETS.md | 3 +-- 6 files changed, 9 insertions(+), 39 deletions(-) delete mode 100644 backend/src/modules/mail/templates/account-validated-parent-coparent.hbs rename backend/src/modules/mail/templates/{account-validated-parent-primary.hbs => account-validated-parent.hbs} (77%) diff --git a/backend/src/modules/mail/mail.service.spec.ts b/backend/src/modules/mail/mail.service.spec.ts index 8f5cbe5..03eb5b0 100644 --- a/backend/src/modules/mail/mail.service.spec.ts +++ b/backend/src/modules/mail/mail.service.spec.ts @@ -44,8 +44,7 @@ describe('MailService (ticket #28)', () => { }); it.each<[ValidationAccountEmailKind, string]>([ - ['parent_primary', 'Compte validé'], - ['parent_coparent', 'Co-parent'], + ['parent', 'Compte parent validé'], ['am', 'Inscription validée'], ])('sendValidatedAccountPasswordSetupEmail (%s) utilise Handlebars + lien token', async (kind, subjectPart) => { const token = '11111111-2222-3333-4444-555555555555'; diff --git a/backend/src/modules/mail/mail.service.ts b/backend/src/modules/mail/mail.service.ts index aa39e3f..79521c8 100644 --- a/backend/src/modules/mail/mail.service.ts +++ b/backend/src/modules/mail/mail.service.ts @@ -5,7 +5,7 @@ import * as Handlebars from 'handlebars'; import { AppConfigService } from '../config/config.service'; /** Ticket #28 — quel template d'email envoyer après validation de compte */ -export type ValidationAccountEmailKind = 'parent_primary' | 'parent_coparent' | 'am'; +export type ValidationAccountEmailKind = 'parent' | 'am'; @Injectable() export class MailService { @@ -18,8 +18,7 @@ export class MailService { private templateBasename(kind: ValidationAccountEmailKind): string { const map: Record = { - parent_primary: 'account-validated-parent-primary', - parent_coparent: 'account-validated-parent-coparent', + parent: 'account-validated-parent', am: 'account-validated-am', }; return map[kind]; @@ -67,8 +66,7 @@ export class MailService { const html = this.getCompiledTemplate(kind)(data) as string; const subjects: Record = { - parent_primary: `${appName} — Compte validé : créez votre mot de passe`, - parent_coparent: `${appName} — Co-parent : créez votre mot de passe`, + parent: `${appName} — Compte parent validé : créez votre mot de passe`, am: `${appName} — Inscription validée : créez votre mot de passe`, }; diff --git a/backend/src/modules/mail/templates/account-validated-parent-coparent.hbs b/backend/src/modules/mail/templates/account-validated-parent-coparent.hbs deleted file mode 100644 index e75c446..0000000 --- a/backend/src/modules/mail/templates/account-validated-parent-coparent.hbs +++ /dev/null @@ -1,14 +0,0 @@ -
-

Bonjour {{prenom}} {{nom}},

-

Le dossier d'inscription sur {{appName}} auquel vous êtes rattaché·e en tant que co-parent a été validé.

- {{#if numeroDossier}} -

Numéro de dossier : {{numeroDossier}}

- {{/if}} -

Vous devez maintenant définir votre mot de passe pour accéder à l'application avec votre propre compte.

-
- Créer mon mot de passe -
-

Si le bouton ne fonctionne pas, copiez ce lien dans votre navigateur :
{{{createPasswordUrl}}}

-
-

Cet email a été envoyé automatiquement par {{appName}}. Merci de ne pas y répondre.

-
diff --git a/backend/src/modules/mail/templates/account-validated-parent-primary.hbs b/backend/src/modules/mail/templates/account-validated-parent.hbs similarity index 77% rename from backend/src/modules/mail/templates/account-validated-parent-primary.hbs rename to backend/src/modules/mail/templates/account-validated-parent.hbs index 3cdb68a..78d82bc 100644 --- a/backend/src/modules/mail/templates/account-validated-parent-primary.hbs +++ b/backend/src/modules/mail/templates/account-validated-parent.hbs @@ -1,10 +1,10 @@

Bonjour {{prenom}} {{nom}},

-

Votre demande d'inscription sur {{appName}} a été validée.

+

Votre compte parent sur {{appName}} a été validé.

{{#if numeroDossier}}

Numéro de dossier : {{numeroDossier}}

{{/if}} -

En tant que demandeur principal, vous devez maintenant définir votre mot de passe pour accéder à l'application.

+

Pour accéder à l'application, veuillez définir votre mot de passe en cliquant sur le bouton ci-dessous.

Créer mon mot de passe
diff --git a/backend/src/routes/user/user.service.ts b/backend/src/routes/user/user.service.ts index 2f3437e..9becd46 100644 --- a/backend/src/routes/user/user.service.ts +++ b/backend/src/routes/user/user.service.ts @@ -286,20 +286,8 @@ export class UserService { savedUser.token_creation_mdp_expire_le = exp; await this.usersRepository.save(savedUser); - let kind: ValidationAccountEmailKind = 'am'; - if (savedUser.role === RoleType.ASSISTANTE_MATERNELLE) { - kind = 'am'; - } else if (savedUser.numero_dossier) { - const parentsDossier = await this.usersRepository.find({ - where: { numero_dossier: savedUser.numero_dossier, role: RoleType.PARENT }, - order: { cree_le: 'ASC' }, - }); - const premier = parentsDossier[0]; - kind = - premier && premier.id !== savedUser.id ? 'parent_coparent' : 'parent_primary'; - } else { - kind = 'parent_primary'; - } + const kind: ValidationAccountEmailKind = + savedUser.role === RoleType.ASSISTANTE_MATERNELLE ? 'am' : 'parent'; await this.mailService.sendValidatedAccountPasswordSetupEmail( { diff --git a/docs/23_LISTE-TICKETS.md b/docs/23_LISTE-TICKETS.md index 934fb6a..a0996d0 100644 --- a/docs/23_LISTE-TICKETS.md +++ b/docs/23_LISTE-TICKETS.md @@ -600,11 +600,10 @@ Installer et configurer Nodemailer pour l'envoi d'emails. Créer les templates d'emails pour la validation des comptes (avec lien création MDP). **Tâches** : -- [x] Template Parent 1 (création MDP) — `account-validated-parent-primary.hbs` +- [x] Template **Parent** (création MDP, parent principal ou co-parent) — `account-validated-parent.hbs` - [x] URL app : Lire depuis `ConfigService.get('app_url')` (lien `/create-password?token=…`) - [x] Nom app : Lire depuis `ConfigService.get('app_name')` - [x] Expéditeur : via `sendEmail` (email_from_name / email_from_address) -- [x] Template Parent 2 (co-parent création MDP) — `account-validated-parent-coparent.hbs` - [x] Template AM (création MDP) — `account-validated-am.hbs` - [x] Intégration Handlebars + copie `.hbs` dans `dist` (`nest-cli.json` assets) - [x] Envoi déclenché dans `UserService.validateUser` (parent / AM sans mot de passe) + renouvellement expiration token