refacto(db): TTL conf in mongo

This commit is contained in:
Julien Froidefond
2025-02-14 17:07:44 +01:00
parent 5d47b307bd
commit ca36f4ce6a
5 changed files with 203 additions and 27 deletions

View File

@@ -0,0 +1,47 @@
import { NextResponse } from "next/server";
import { ConfigDBService } from "@/lib/services/config-db.service";
export async function GET() {
try {
const config = await ConfigDBService.getTTLConfig();
return NextResponse.json(config);
} catch (error) {
console.error("Erreur lors de la récupération de la configuration TTL:", error);
if (error instanceof Error) {
if (error.message === "Utilisateur non authentifié") {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}
}
return NextResponse.json(
{ error: "Erreur lors de la récupération de la configuration TTL" },
{ status: 500 }
);
}
}
export async function POST(request: Request) {
try {
const data = await request.json();
const config = await ConfigDBService.saveTTLConfig(data);
return NextResponse.json({
message: "Configuration TTL sauvegardée avec succès",
config: {
defaultTTL: config.defaultTTL,
homeTTL: config.homeTTL,
librariesTTL: config.librariesTTL,
seriesTTL: config.seriesTTL,
booksTTL: config.booksTTL,
imagesTTL: config.imagesTTL,
},
});
} catch (error) {
console.error("Erreur lors de la sauvegarde de la configuration TTL:", error);
if (error instanceof Error && error.message === "Utilisateur non authentifié") {
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
}
return NextResponse.json(
{ error: "Erreur lors de la sauvegarde de la configuration TTL" },
{ status: 500 }
);
}
}