Checkpoint: Ajout de l'onglet "Paramétrage" dans la page Ventilation FreePro :
- Table DB freeproSettings (URL portail, credentials, fréquence, date antériorité, statut dernière récupération) - Service freeproAutoImport.ts : connexion HTTP au portail FreePro, téléchargement CSV, pipeline d'import - Procédures tRPC : getSettings, saveSettings, testConnection, forceImport - Job périodique en mémoire (daily/weekly/monthly) via setInterval - Frontend : wrapper Tabs (onglet 1 = Import & Historique, onglet 2 = Paramétrage) - Onglet Paramétrage : credentials, fréquence, date antériorité, bouton "Forcer récupération", statut - Tests unitaires : 8 tests passés
This commit is contained in:
72
server/db.ts
72
server/db.ts
@@ -1015,3 +1015,75 @@ export async function deleteFreeproImport(importId: number): Promise<void> {
|
||||
await db.delete(freeproVentilationLines).where(eq(freeproVentilationLines.importId, importId));
|
||||
await db.delete(freeproImports).where(eq(freeproImports.id, importId));
|
||||
}
|
||||
|
||||
// ============= FREEPRO SETTINGS OPERATIONS =============
|
||||
|
||||
import {
|
||||
freeproSettings,
|
||||
InsertFreeproSettings,
|
||||
FreeproSettings,
|
||||
} from "../drizzle/schema";
|
||||
|
||||
/** Récupère les paramètres FreePro d'un utilisateur */
|
||||
export async function getFreeproSettings(userId: number): Promise<FreeproSettings | null> {
|
||||
const db = await getDb();
|
||||
if (!db) return null;
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(freeproSettings)
|
||||
.where(eq(freeproSettings.userId, userId))
|
||||
.limit(1);
|
||||
return rows[0] ?? null;
|
||||
}
|
||||
|
||||
/** Crée ou met à jour les paramètres FreePro d'un utilisateur */
|
||||
export async function upsertFreeproSettings(
|
||||
userId: number,
|
||||
data: Partial<Omit<InsertFreeproSettings, "id" | "userId" | "createdAt" | "updatedAt">>
|
||||
): Promise<void> {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
const existing = await getFreeproSettings(userId);
|
||||
if (existing) {
|
||||
await db
|
||||
.update(freeproSettings)
|
||||
.set({ ...data, updatedAt: new Date() })
|
||||
.where(eq(freeproSettings.userId, userId));
|
||||
} else {
|
||||
await db.insert(freeproSettings).values({
|
||||
userId,
|
||||
portalUrl: data.portalUrl ?? "https://pro.free.fr",
|
||||
loginEmail: data.loginEmail ?? null,
|
||||
loginPassword: data.loginPassword ?? null,
|
||||
frequency: data.frequency ?? "manual",
|
||||
maxAnteriority: data.maxAnteriority ?? null,
|
||||
autoEnabled: data.autoEnabled ?? 0,
|
||||
lastSuccessAt: data.lastSuccessAt ?? null,
|
||||
lastStatus: data.lastStatus ?? null,
|
||||
lastImportCount: data.lastImportCount ?? 0,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/** Met à jour uniquement le statut de la dernière récupération FreePro */
|
||||
export async function updateFreeproLastRun(
|
||||
userId: number,
|
||||
status: string,
|
||||
importCount: number,
|
||||
success: boolean
|
||||
): Promise<void> {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
const update: Partial<InsertFreeproSettings> = {
|
||||
lastStatus: status,
|
||||
lastImportCount: importCount,
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
if (success) {
|
||||
update.lastSuccessAt = new Date();
|
||||
}
|
||||
await db
|
||||
.update(freeproSettings)
|
||||
.set(update)
|
||||
.where(eq(freeproSettings.userId, userId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user