52 lines
1.6 KiB
TypeScript
52 lines
1.6 KiB
TypeScript
import { getDb } from './db';
|
|
import { emailTemplates } from '../drizzle/schema';
|
|
import { eq } from 'drizzle-orm';
|
|
|
|
/**
|
|
* Initialise le template d'email pour les attestations s'il n'existe pas déjà
|
|
*/
|
|
export async function initAttestationTemplate() {
|
|
const db = await getDb();
|
|
if (!db) {
|
|
console.warn('[initTemplates] Database not available, skipping template initialization');
|
|
return;
|
|
}
|
|
|
|
try {
|
|
// Vérifier si le template attestation existe déjà
|
|
const existing = await db
|
|
.select()
|
|
.from(emailTemplates)
|
|
.where(eq(emailTemplates.type, 'attestation'))
|
|
.limit(1);
|
|
|
|
if (existing.length > 0) {
|
|
console.log('[initTemplates] Template attestation already exists');
|
|
return;
|
|
}
|
|
|
|
// Créer le template par défaut
|
|
await db.insert(emailTemplates).values({
|
|
type: 'attestation',
|
|
titre: 'Attestation de formation',
|
|
bodyContent: `<p>Bonjour {{prenomApprenant}} {{nomApprenant}},</p>
|
|
|
|
<p>Nous vous remercions d'avoir participé à la formation <strong>{{nomFormation}}</strong>.</p>
|
|
|
|
<p>Vous trouverez ci-joint votre attestation de formation.</p>
|
|
|
|
<p>Nous espérons que cette formation vous a été bénéfique et nous vous souhaitons beaucoup de succès dans vos projets futurs.</p>
|
|
|
|
<p>Cordialement,<br>
|
|
L'équipe de formation</p>`,
|
|
couleurPrincipale: '#283581',
|
|
couleurSecondaire: '#0578BE',
|
|
piedDePage: 'Cet email a été envoyé automatiquement, merci de ne pas y répondre.',
|
|
});
|
|
|
|
console.log('[initTemplates] Template attestation created successfully');
|
|
} catch (error) {
|
|
console.error('[initTemplates] Error creating attestation template:', error);
|
|
}
|
|
}
|