feat: purger les contenus expirés ou anciens
This commit is contained in:
@@ -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) }))
|
||||
|
||||
Reference in New Issue
Block a user