Checkpoint: Ajout d'un template d'email personnalisable pour l'envoi des attestations de formation. Le template utilise des variables dynamiques ({{prenomApprenant}}, {{nomApprenant}}, {{nomFormation}}) et peut être modifié depuis l'interface de gestion des templates. Déployé sur le VPS avec migration SQL.
This commit is contained in:
@@ -1158,25 +1158,28 @@ export async function sendAttestationEmail(params: {
|
||||
formationNom: string;
|
||||
pdfUrl: string;
|
||||
}): Promise<boolean> {
|
||||
const content = `
|
||||
<h2>Votre attestation de formation</h2>
|
||||
|
||||
<p>Bonjour ${params.apprenantPrenom} ${params.apprenantNom},</p>
|
||||
|
||||
<p>Nous avons le plaisir de vous transmettre votre attestation de formation pour :</p>
|
||||
|
||||
<div class="info-box" style="background-color: #dbeafe; border-left-color: #3b82f6;">
|
||||
<h3>${params.formationNom}</h3>
|
||||
</div>
|
||||
|
||||
<p>Vous trouverez votre attestation en pièce jointe de cet email.</p>
|
||||
|
||||
<p>Cette attestation certifie votre participation à la formation et peut être utilisée pour votre dossier professionnel.</p>
|
||||
|
||||
<p>Nous vous remercions pour votre participation et vous souhaitons une excellente continuation.</p>
|
||||
|
||||
<p>Cordialement,<br/>L'équipe Formation</p>
|
||||
`;
|
||||
// Récupérer le template attestation depuis la base de données
|
||||
const { getDb } = await import('./db');
|
||||
const { emailTemplates } = await import('../drizzle/schema');
|
||||
const { eq } = await import('drizzle-orm');
|
||||
|
||||
const db = await getDb();
|
||||
if (!db) {
|
||||
throw new Error('Database not available');
|
||||
}
|
||||
|
||||
const templates = await db.select().from(emailTemplates).where(eq(emailTemplates.type, 'attestation')).limit(1);
|
||||
if (templates.length === 0) {
|
||||
throw new Error('Template attestation not found');
|
||||
}
|
||||
|
||||
const template = templates[0];
|
||||
|
||||
// Remplacer les variables dans le template
|
||||
let content = template.bodyContent;
|
||||
content = content.replace(/{{prenomApprenant}}/g, params.apprenantPrenom);
|
||||
content = content.replace(/{{nomApprenant}}/g, params.apprenantNom);
|
||||
content = content.replace(/{{nomFormation}}/g, params.formationNom);
|
||||
|
||||
// Récupérer le PDF (depuis URL ou chemin local)
|
||||
let pdfBuffer: Buffer;
|
||||
|
||||
Reference in New Issue
Block a user