true message
This commit is contained in:
121
server/db.ts
121
server/db.ts
@@ -5,7 +5,6 @@ import {
|
||||
users,
|
||||
formations,
|
||||
apprenants,
|
||||
formateurs,
|
||||
sequences,
|
||||
datesFormation,
|
||||
inscriptions,
|
||||
@@ -19,13 +18,10 @@ import {
|
||||
InsertInscription,
|
||||
InsertFormation,
|
||||
InsertApprenant,
|
||||
InsertFormateur,
|
||||
InsertRappel,
|
||||
Sequence,
|
||||
DateFormation,
|
||||
Apprenant,
|
||||
Formation,
|
||||
Formateur,
|
||||
EmailTemplate,
|
||||
InsertEmailTemplate
|
||||
} from "../drizzle/schema";
|
||||
@@ -660,120 +656,3 @@ export async function updateEmailConfig(id: number, data: Partial<InsertEmailCon
|
||||
})
|
||||
.where(eq(emailConfig.id, id));
|
||||
}
|
||||
|
||||
// ===== FORMATEURS =====
|
||||
|
||||
/**
|
||||
* Récupérer tous les formateurs actifs
|
||||
*/
|
||||
export async function getFormateurs() {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
|
||||
const result = await db.select().from(formateurs).where(eq(formateurs.actif, true));
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Créer un nouveau formateur
|
||||
*/
|
||||
export async function createFormateur(data: InsertFormateur) {
|
||||
const db = await getDb();
|
||||
if (!db) return null;
|
||||
|
||||
const result = await db.insert(formateurs).values(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprimer un formateur (désactivation logique)
|
||||
*/
|
||||
export async function deleteFormateur(id: number) {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
|
||||
await db.update(formateurs).set({ actif: false }).where(eq(formateurs.id, id));
|
||||
}
|
||||
|
||||
// ===== RAPPELS =====
|
||||
|
||||
/**
|
||||
* Récupérer tous les rappels
|
||||
*/
|
||||
export async function getRappels() {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
|
||||
const { rappels } = await import("../drizzle/schema");
|
||||
const result = await db.select().from(rappels);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Créer un nouveau rappel
|
||||
*/
|
||||
export async function createRappel(data: InsertRappel) {
|
||||
const db = await getDb();
|
||||
if (!db) return null;
|
||||
|
||||
const { rappels } = await import("../drizzle/schema");
|
||||
const result = await db.insert(rappels).values(data);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Mettre à jour un rappel
|
||||
*/
|
||||
export async function updateRappel(id: number, data: Partial<InsertRappel>) {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
|
||||
const { rappels } = await import("../drizzle/schema");
|
||||
await db.update(rappels).set({
|
||||
...data,
|
||||
updatedAt: new Date(),
|
||||
}).where(eq(rappels.id, id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Supprimer un rappel
|
||||
*/
|
||||
export async function deleteRappel(id: number) {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
|
||||
const { rappels } = await import("../drizzle/schema");
|
||||
await db.delete(rappels).where(eq(rappels.id, id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Enregistrer l'envoi d'un rappel
|
||||
*/
|
||||
export async function enregistrerRappelEnvoye(rappelId: number, inscriptionId: number) {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
|
||||
const { rappelsEnvoyes } = await import("../drizzle/schema");
|
||||
await db.insert(rappelsEnvoyes).values({
|
||||
rappelId,
|
||||
inscriptionId,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Vérifier si un rappel a déjà été envoyé
|
||||
*/
|
||||
export async function rappelDejaEnvoye(rappelId: number, inscriptionId: number) {
|
||||
const db = await getDb();
|
||||
if (!db) return false;
|
||||
|
||||
const { rappelsEnvoyes } = await import("../drizzle/schema");
|
||||
const result = await db.select().from(rappelsEnvoyes)
|
||||
.where(and(
|
||||
eq(rappelsEnvoyes.rappelId, rappelId),
|
||||
eq(rappelsEnvoyes.inscriptionId, inscriptionId)
|
||||
))
|
||||
.limit(1);
|
||||
|
||||
return result.length > 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user