Rollen Chunk 5: Genehmigungs-Status mit Eigen-UI
This commit is contained in:
1 parent
8b6792a7f9
commit
c670b583c9
1 file changed
+13
-1
@@ -15,11 +15,13 @@ import {
|
|||||||
import { getFederalState } from "@/lib/region";
|
import { getFederalState } from "@/lib/region";
|
||||||
import {
|
import {
|
||||||
ensureYearSettings,
|
ensureYearSettings,
|
||||||
|
getUserRole,
|
||||||
getWeeklyTargets,
|
getWeeklyTargets,
|
||||||
listDeletedVacationRequests,
|
listDeletedVacationRequests,
|
||||||
listVacationDays,
|
listVacationDays,
|
||||||
listVacationRequests,
|
listVacationRequests,
|
||||||
saveVacationRequest,
|
saveVacationRequest,
|
||||||
|
sumPendingUnitsByYear,
|
||||||
sumVacationUnitsByYear,
|
sumVacationUnitsByYear,
|
||||||
} from "@/lib/repository";
|
} from "@/lib/repository";
|
||||||
|
|
||||||
@@ -134,10 +136,13 @@ export async function POST(request: Request) {
|
|||||||
}
|
}
|
||||||
for (const [rangeYear, newUnits] of newUnitsByYear) {
|
for (const [rangeYear, newUnits] of newUnitsByYear) {
|
||||||
const settings = ensureYearSettings(db, user.id, rangeYear);
|
const settings = ensureYearSettings(db, user.id, rangeYear);
|
||||||
|
const committed =
|
||||||
|
sumVacationUnitsByYear(db, user.id, rangeYear) +
|
||||||
|
sumPendingUnitsByYear(db, user.id, rangeYear);
|
||||||
const remaining = calculateVacationBalance(
|
const remaining = calculateVacationBalance(
|
||||||
settings.entitlementUnits,
|
settings.entitlementUnits,
|
||||||
settings.carryoverUnits,
|
settings.carryoverUnits,
|
||||||
sumVacationUnitsByYear(db, user.id, rangeYear),
|
committed,
|
||||||
);
|
);
|
||||||
if (newUnits > remaining) {
|
if (newUnits > remaining) {
|
||||||
return errorResponse(
|
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, {
|
const saved = saveVacationRequest(db, user.id, {
|
||||||
startDate: startDate as string,
|
startDate: startDate as string,
|
||||||
endDate: endDate as string,
|
endDate: endDate as string,
|
||||||
dayFraction,
|
dayFraction,
|
||||||
days: eligible.map((date) => ({ date, units: unitPerDay })),
|
days: eligible.map((date) => ({ date, units: unitPerDay })),
|
||||||
|
status,
|
||||||
});
|
});
|
||||||
return NextResponse.json(saved, { status: 201 });
|
return NextResponse.json(saved, { status: 201 });
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user