Rollen Chunk 5: Genehmigungs-Status mit Eigen-UI
This commit is contained in:
1 parent
af03a5d416
commit
8b6792a7f9
1 file changed
+11
-2
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
import { authedUser } from "@/lib/auth";
|
||||
import { getDb, initializeDatabase } from "@/lib/db";
|
||||
import { errorResponse } from "@/lib/http";
|
||||
import { deleteVacationRequest } from "@/lib/repository";
|
||||
import { deleteVacationRequest, getVacationRequest, purgeVacationRequest } from "@/lib/repository";
|
||||
|
||||
export async function DELETE(
|
||||
request: Request,
|
||||
@@ -18,7 +18,16 @@ export async function DELETE(
|
||||
}
|
||||
const db = getDb();
|
||||
initializeDatabase(db);
|
||||
if (!deleteVacationRequest(db, user.id, Number(id))) {
|
||||
const existing = getVacationRequest(db, user.id, Number(id));
|
||||
if (!existing) {
|
||||
return errorResponse(404, "notFound", "No vacation request with this id.");
|
||||
}
|
||||
// Anfragen und Ablehnungen verschwinden spurlos, bestaetigte in den Papierkorb.
|
||||
const removed =
|
||||
existing.status === "bestätigt"
|
||||
? deleteVacationRequest(db, user.id, Number(id))
|
||||
: purgeVacationRequest(db, user.id, Number(id));
|
||||
if (!removed) {
|
||||
return errorResponse(404, "notFound", "No vacation request with this id.");
|
||||
}
|
||||
return NextResponse.json({ deleted: true });
|
||||
|
||||
Reference in new issue
Block a user