Checkpoint: Améliorations Factures BAP : suppression colonne Abonnement, mode d'export configurable (navigateur/dossier), génération PDF annoté avec zone blanche (CAPEX/OPEX | BAP | Destinataire + signature du service) lors du clic BAP, historique BAP dans le menu Traçabilité, table bapHistory en DB.
This commit is contained in:
37
server/db.ts
37
server/db.ts
@@ -38,7 +38,10 @@ import {
|
||||
Signature,
|
||||
serviceSignatures,
|
||||
InsertServiceSignature,
|
||||
ServiceSignature
|
||||
ServiceSignature,
|
||||
bapHistory,
|
||||
InsertBapHistory,
|
||||
BapHistory
|
||||
} from "../drizzle/schema";
|
||||
import { ENV } from './_core/env';
|
||||
|
||||
@@ -776,3 +779,35 @@ export async function deleteServiceSignature(userId: number, serviceName: string
|
||||
await db.delete(serviceSignatures).where(eq(serviceSignatures.id, match.id));
|
||||
}
|
||||
}
|
||||
|
||||
// ============= BAP HISTORY HELPERS =============
|
||||
export async function createBapHistoryEntry(data: InsertBapHistory): Promise<BapHistory> {
|
||||
const db = await getDb();
|
||||
if (!db) throw new Error("Database not available");
|
||||
const result = await db.insert(bapHistory).values(data);
|
||||
const insertId = (result[0] as any).insertId;
|
||||
const created = await getBapHistoryById(insertId);
|
||||
if (!created) throw new Error("Failed to retrieve created BAP history entry");
|
||||
return created;
|
||||
}
|
||||
|
||||
export async function getBapHistoryById(id: number): Promise<BapHistory | undefined> {
|
||||
const db = await getDb();
|
||||
if (!db) return undefined;
|
||||
const results = await db.select().from(bapHistory).where(eq(bapHistory.id, id));
|
||||
return results[0];
|
||||
}
|
||||
|
||||
export async function getBapHistoryByUser(userId: number): Promise<BapHistory[]> {
|
||||
const db = await getDb();
|
||||
if (!db) return [];
|
||||
return db.select().from(bapHistory)
|
||||
.where(eq(bapHistory.userId, userId))
|
||||
.orderBy(desc(bapHistory.validatedAt));
|
||||
}
|
||||
|
||||
export async function deleteBapHistoryEntry(id: number): Promise<void> {
|
||||
const db = await getDb();
|
||||
if (!db) return;
|
||||
await db.delete(bapHistory).where(eq(bapHistory.id, id));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user