feat: purge import history by retention
This commit is contained in:
@@ -4,6 +4,7 @@ import { BAP_MIN_QUALITY_SCORE, meetsBapQualityThreshold } from "@shared/bapElig
|
||||
import { requiresBapBeforeOriginalPdfExport } from "@shared/bapExportGuard";
|
||||
import { calculateInvoiceQualityScore, withCalculatedInvoiceQuality } from "@shared/invoiceQuality";
|
||||
import { normalizeImportLogPagination } from "@shared/importLogPagination";
|
||||
import { getImportLogRetentionCutoff, isImportLogRetentionMonths } from "@shared/importLogRetention";
|
||||
import { webPortalUrlSchema } from "./webPortalUrl";
|
||||
|
||||
interface Condition {
|
||||
@@ -50,6 +51,8 @@ import {
|
||||
getImportLogsByUser,
|
||||
getImportLogsWithDetailsByUser,
|
||||
deleteAllImportLogs,
|
||||
countImportLogsBefore,
|
||||
deleteImportLogsBefore,
|
||||
getLlmLogsBySourceFile,
|
||||
getLlmLogsByInvoice,
|
||||
getImportSettingsByUser,
|
||||
@@ -1748,6 +1751,34 @@ export const appRouter = router({
|
||||
}
|
||||
return { success: true };
|
||||
}),
|
||||
|
||||
retentionPreview: protectedProcedure
|
||||
.input(z.object({ months: z.number().int() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
if (ctx.user.role !== "admin") {
|
||||
throw new TRPCError({ code: "FORBIDDEN", message: "Réservé aux administrateurs." });
|
||||
}
|
||||
if (!isImportLogRetentionMonths(input.months)) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Durée de rétention invalide." });
|
||||
}
|
||||
const cutoff = getImportLogRetentionCutoff(input.months);
|
||||
const count = await countImportLogsBefore(cutoff);
|
||||
return { months: input.months, cutoff, count };
|
||||
}),
|
||||
|
||||
purgeBeforeRetention: protectedProcedure
|
||||
.input(z.object({ months: z.number().int() }))
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
if (ctx.user.role !== "admin") {
|
||||
throw new TRPCError({ code: "FORBIDDEN", message: "Réservé aux administrateurs." });
|
||||
}
|
||||
if (!isImportLogRetentionMonths(input.months)) {
|
||||
throw new TRPCError({ code: "BAD_REQUEST", message: "Durée de rétention invalide." });
|
||||
}
|
||||
const cutoff = getImportLogRetentionCutoff(input.months);
|
||||
const deletedCount = await deleteImportLogsBefore(cutoff);
|
||||
return { months: input.months, cutoff, deletedCount };
|
||||
}),
|
||||
}),
|
||||
|
||||
// ============= LLM LOGS ROUTES =============
|
||||
|
||||
Reference in New Issue
Block a user