Rollen Chunk 5: Genehmigungs-Status mit Eigen-UI
Docker Image / test (push) Canceled after 0s
Docker Image / image (push) Canceled after 0s

This commit is contained in:
loki committed 2026-10-11 19:31:39 +02:00
1 parent 8b6792a7f9
commit c670b583c9
1 file changed
+13 -1
+13 -1
View File
@@ -15,11 +15,13 @@ import {
import { getFederalState } from "@/lib/region";
import {
ensureYearSettings,
getUserRole,
getWeeklyTargets,
listDeletedVacationRequests,
listVacationDays,
listVacationRequests,
saveVacationRequest,
sumPendingUnitsByYear,
sumVacationUnitsByYear,
} from "@/lib/repository";
@@ -134,10 +136,13 @@ export async function POST(request: Request) {
}
for (const [rangeYear, newUnits] of newUnitsByYear) {
const settings = ensureYearSettings(db, user.id, rangeYear);
const committed =
sumVacationUnitsByYear(db, user.id, rangeYear) +
sumPendingUnitsByYear(db, user.id, rangeYear);
const remaining = calculateVacationBalance(
settings.entitlementUnits,
settings.carryoverUnits,
sumVacationUnitsByYear(db, user.id, rangeYear),
committed,
);
if (newUnits > remaining) {
return errorResponse(
@@ -148,11 +153,18 @@ export async function POST(request: Request) {
);
}
}
// Normale Benutzer stellen Anfragen (beantragt), Teamleiter und Admins
// buchen direkt (bestätigt); ohne Anmeldung wie bisher bestätigt.
const status =
user.id !== "" && getUserRole(db, user.id) === "benutzer"
? "beantragt"
: "bestätigt";
const saved = saveVacationRequest(db, user.id, {
startDate: startDate as string,
endDate: endDate as string,
dayFraction,
days: eligible.map((date) => ({ date, units: unitPerDay })),
status,
});
return NextResponse.json(saved, { status: 201 });
}