Checkpoint: Refonte majeure du système de rappels : sélection granulaire au niveau des dates de formation individuelles (dateFormationId) au lieu des séquences. Permet de choisir précisément quelles dates d'une séquence recevront un rappel. Interface hiérarchique avec séquences dépliables et checkboxes par date. Scheduler adapté pour traiter date par date.
This commit is contained in:
36
server/db.ts
36
server/db.ts
@@ -30,7 +30,7 @@ import {
|
||||
rappels,
|
||||
InsertRappel,
|
||||
Rappel,
|
||||
rappelSequences
|
||||
rappelDates
|
||||
} from "../drizzle/schema";
|
||||
import { ENV } from './_core/env';
|
||||
|
||||
@@ -972,18 +972,18 @@ export async function getRappels() {
|
||||
|
||||
const allRappels = await db.select().from(rappels).orderBy(rappels.joursAvant);
|
||||
|
||||
// Pour chaque rappel, récupérer les séquences associées
|
||||
const rappelsWithSequences = await Promise.all(
|
||||
// Pour chaque rappel, récupérer les dates de formation associées
|
||||
const rappelsWithDates = await Promise.all(
|
||||
allRappels.map(async (rappel) => {
|
||||
const sequenceIds = await getRappelSequences(rappel.id);
|
||||
const dateFormationIds = await getRappelDates(rappel.id);
|
||||
return {
|
||||
...rappel,
|
||||
sequenceIds,
|
||||
dateFormationIds,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
return rappelsWithSequences;
|
||||
return rappelsWithDates;
|
||||
}
|
||||
|
||||
export async function getRappelById(id: number): Promise<Rappel | undefined> {
|
||||
@@ -1037,40 +1037,40 @@ export async function deleteRappel(id: number) {
|
||||
if (!db) throw new Error("Database not available");
|
||||
|
||||
// Supprimer d'abord les associations
|
||||
await db.delete(rappelSequences).where(eq(rappelSequences.rappelId, id));
|
||||
await db.delete(rappelDates).where(eq(rappelDates.rappelId, id));
|
||||
// Puis le rappel
|
||||
await db.delete(rappels).where(eq(rappels.id, id));
|
||||
}
|
||||
|
||||
// ==================== RAPPEL SEQUENCES ====================
|
||||
// ==================== RAPPEL DATES ====================
|
||||
|
||||
export async function createRappelSequences(rappelId: number, sequenceIds: number[]) {
|
||||
export async function createRappelDates(rappelId: number, dateFormationIds: number[]) {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
|
||||
if (sequenceIds.length === 0) return;
|
||||
if (dateFormationIds.length === 0) return;
|
||||
|
||||
const values = sequenceIds.map(sequenceId => ({
|
||||
const values = dateFormationIds.map(dateFormationId => ({
|
||||
rappelId,
|
||||
sequenceId,
|
||||
dateFormationId,
|
||||
}));
|
||||
|
||||
await db.insert(rappelSequences).values(values);
|
||||
await db.insert(rappelDates).values(values);
|
||||
}
|
||||
|
||||
export async function deleteRappelSequences(rappelId: number) {
|
||||
export async function deleteRappelDates(rappelId: number) {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
|
||||
await db.delete(rappelSequences).where(eq(rappelSequences.rappelId, rappelId));
|
||||
await db.delete(rappelDates).where(eq(rappelDates.rappelId, rappelId));
|
||||
}
|
||||
|
||||
export async function getRappelSequences(rappelId: number): Promise<number[]> {
|
||||
export async function getRappelDates(rappelId: number): Promise<number[]> {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
|
||||
const results = await db.select().from(rappelSequences).where(eq(rappelSequences.rappelId, rappelId));
|
||||
return results.map(r => r.sequenceId);
|
||||
const results = await db.select().from(rappelDates).where(eq(rappelDates.rappelId, rappelId));
|
||||
return results.map(r => r.dateFormationId);
|
||||
}
|
||||
|
||||
export async function updateRappelExecution(id: number) {
|
||||
|
||||
Reference in New Issue
Block a user