Enforce daily working hour limits for security guards
Implement daily hour limit checks for guard assignments based on CCNL regulations, preventing assignments that exceed 9 hours per day. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/Jxn533V
This commit is contained in:
parent
19158357fb
commit
1c34d3f79e
4
.replit
4
.replit
@ -39,6 +39,10 @@ externalPort = 5000
|
|||||||
localPort = 43267
|
localPort = 43267
|
||||||
externalPort = 3003
|
externalPort = 3003
|
||||||
|
|
||||||
|
[[ports]]
|
||||||
|
localPort = 44575
|
||||||
|
externalPort = 5173
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
PORT = "5000"
|
PORT = "5000"
|
||||||
|
|
||||||
|
|||||||
@ -1326,6 +1326,7 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
.from(shiftAssignments)
|
.from(shiftAssignments)
|
||||||
.where(eq(shiftAssignments.guardId, guard.id));
|
.where(eq(shiftAssignments.guardId, guard.id));
|
||||||
|
|
||||||
|
// Check for time overlaps
|
||||||
for (const existing of existingAssignments) {
|
for (const existing of existingAssignments) {
|
||||||
const hasOverlap =
|
const hasOverlap =
|
||||||
plannedStart < existing.plannedEndTime &&
|
plannedStart < existing.plannedEndTime &&
|
||||||
@ -1338,6 +1339,34 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CCNL: Check daily hour limit (max 9h/day)
|
||||||
|
const maxDailyHours = 9;
|
||||||
|
let dailyHoursAlreadyAssigned = 0;
|
||||||
|
|
||||||
|
for (const existing of existingAssignments) {
|
||||||
|
// Check if assignment is on the same day
|
||||||
|
const existingDate = new Date(existing.plannedStartTime);
|
||||||
|
if (
|
||||||
|
existingDate.getUTCFullYear() === actualYear &&
|
||||||
|
existingDate.getUTCMonth() === actualMonth &&
|
||||||
|
existingDate.getUTCDate() === actualDay
|
||||||
|
) {
|
||||||
|
const assignmentHours = differenceInHours(
|
||||||
|
existing.plannedEndTime,
|
||||||
|
existing.plannedStartTime
|
||||||
|
);
|
||||||
|
dailyHoursAlreadyAssigned += assignmentHours;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if new assignment would exceed daily limit
|
||||||
|
if (dailyHoursAlreadyAssigned + durationHours > maxDailyHours) {
|
||||||
|
throw new Error(
|
||||||
|
`Limite giornaliero superato: la guardia ha già ${dailyHoursAlreadyAssigned}h assegnate il ${shiftDate.toLocaleDateString('it-IT')}. ` +
|
||||||
|
`Aggiungendo ${durationHours}h si supererebbero le ${maxDailyHours}h massime giornaliere (CCNL).`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Create assignment for this day
|
// Create assignment for this day
|
||||||
const [assignment] = await tx.insert(shiftAssignments).values({
|
const [assignment] = await tx.insert(shiftAssignments).values({
|
||||||
shiftId: shift.id,
|
shiftId: shift.id,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user