feat: purger les contenus expirés ou anciens
All checks were successful
Deploy Production / deploy (push) Has been skipped
Deploy Recette / deploy (push) Successful in 1m30s
Validation applicative / TypeScript, tests et build (push) Successful in 1m52s

This commit is contained in:
manus-admin
2026-10-09 15:46:52 +02:00
parent 648ff4ca75
commit 716431ede3
5 changed files with 255 additions and 18 deletions

View File

@@ -11,6 +11,9 @@ import {
getAapDistinctValues,
purgeVeilleItems,
purgeAapItems,
purgeVeilleItemsOlderThan,
purgeExpiredAapItems,
purgeAapItemsOlderThan,
getAllSettings,
setSettings,
getImportLogs,
@@ -56,6 +59,28 @@ const adminProcedure = protectedProcedure.use(({ ctx, next }) => {
return next({ ctx });
});
const retentionMonths = z.union([
z.literal(1), z.literal(3), z.literal(6), z.literal(12), z.literal(18), z.literal(24),
]);
const veillePurgeInput = z.object({
scope: z.enum(["all", "older_than"]),
months: retentionMonths.optional(),
}).superRefine((value, ctx) => {
if (value.scope === "older_than" && value.months === undefined) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "La durée de conservation est requise." });
}
});
const aapPurgeInput = z.object({
scope: z.enum(["all", "expired", "older_than"]),
months: retentionMonths.optional(),
}).superRefine((value, ctx) => {
if (value.scope === "older_than" && value.months === undefined) {
ctx.addIssue({ code: z.ZodIssueCode.custom, message: "La durée de conservation est requise." });
}
});
// ─── Router principal ─────────────────────────────────────────────────────────
export const appRouter = router({
@@ -127,10 +152,14 @@ export const appRouter = router({
filters: publicProcedure.query(async () => {
return getVeilleDistinctValues();
}),
purge: adminProcedure.mutation(async () => {
const count = await purgeVeilleItems();
return { success: true, deleted: count };
}),
purge: adminProcedure
.input(veillePurgeInput)
.mutation(async ({ input }) => {
const count = input.scope === "all"
? await purgeVeilleItems()
: await purgeVeilleItemsOlderThan(input.months!);
return { success: true, deleted: count, scope: input.scope, months: input.months ?? null };
}),
reclassifyWithAI: adminProcedure
.input(z.object({ limit: z.number().int().positive().max(200).default(50) }))
@@ -238,10 +267,16 @@ export const appRouter = router({
filters: publicProcedure.query(async () => {
return getAapDistinctValues();
}),
purge: adminProcedure.mutation(async () => {
const count = await purgeAapItems();
return { success: true, deleted: count };
}),
purge: adminProcedure
.input(aapPurgeInput)
.mutation(async ({ input }) => {
const count = input.scope === "all"
? await purgeAapItems()
: input.scope === "expired"
? await purgeExpiredAapItems()
: await purgeAapItemsOlderThan(input.months!);
return { success: true, deleted: count, scope: input.scope, months: input.months ?? null };
}),
reclassifyWithAI: adminProcedure
.input(z.object({ limit: z.number().int().positive().max(200).default(50) }))