Checkpoint: Correction et finalisation du template email attestation : ajout du type 'attestation' dans le frontend, création automatique du template au démarrage de l'application, déploiement réussi sur le VPS. Le template est maintenant visible et modifiable dans l'interface de gestion des templates.
This commit is contained in:
@@ -14,6 +14,7 @@ import { serveStatic, setupVite } from "./vite";
|
||||
import { initRappelScheduler } from "../rappelScheduler";
|
||||
import { initRappelRetryScheduler } from "../rappelRetry";
|
||||
import { initFail2BanAlertSystem } from "../fail2banAlertService";
|
||||
import { initAttestationTemplate } from "../initTemplates";
|
||||
|
||||
function isPortAvailable(port: number): Promise<boolean> {
|
||||
return new Promise(resolve => {
|
||||
@@ -75,6 +76,9 @@ async function startServer() {
|
||||
server.listen(port, () => {
|
||||
console.log(`Server running on http://localhost:${port}/`);
|
||||
|
||||
// Initialiser les templates par défaut
|
||||
initAttestationTemplate();
|
||||
|
||||
// Initialiser le scheduler de rappels automatiques
|
||||
initRappelScheduler();
|
||||
|
||||
|
||||
51
server/initTemplates.ts
Normal file
51
server/initTemplates.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user