Improve guard shift assignment with planned start and end times
Update the schema for shift assignments to include planned start and end times, and extend the insert schema to validate these times, ensuring guards are assigned to specific time slots. 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/McZSLgC
This commit is contained in:
parent
18e219e118
commit
1caf5c4199
@ -257,10 +257,14 @@ export const shiftAssignments = pgTable("shift_assignments", {
|
|||||||
shiftId: varchar("shift_id").notNull().references(() => shifts.id, { onDelete: "cascade" }),
|
shiftId: varchar("shift_id").notNull().references(() => shifts.id, { onDelete: "cascade" }),
|
||||||
guardId: varchar("guard_id").notNull().references(() => guards.id, { onDelete: "cascade" }),
|
guardId: varchar("guard_id").notNull().references(() => guards.id, { onDelete: "cascade" }),
|
||||||
|
|
||||||
|
// Planned shift times (when the guard is scheduled to work)
|
||||||
|
plannedStartTime: timestamp("planned_start_time").notNull(),
|
||||||
|
plannedEndTime: timestamp("planned_end_time").notNull(),
|
||||||
|
|
||||||
assignedAt: timestamp("assigned_at").defaultNow(),
|
assignedAt: timestamp("assigned_at").defaultNow(),
|
||||||
confirmedAt: timestamp("confirmed_at"),
|
confirmedAt: timestamp("confirmed_at"),
|
||||||
|
|
||||||
// Actual check-in/out times
|
// Actual check-in/out times (recorded when guard clocks in/out)
|
||||||
checkInTime: timestamp("check_in_time"),
|
checkInTime: timestamp("check_in_time"),
|
||||||
checkOutTime: timestamp("check_out_time"),
|
checkOutTime: timestamp("check_out_time"),
|
||||||
});
|
});
|
||||||
@ -700,10 +704,25 @@ export const insertShiftFormSchema = z.object({
|
|||||||
status: z.enum(["planned", "active", "completed", "cancelled"]).default("planned"),
|
status: z.enum(["planned", "active", "completed", "cancelled"]).default("planned"),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const insertShiftAssignmentSchema = createInsertSchema(shiftAssignments).omit({
|
export const insertShiftAssignmentSchema = createInsertSchema(shiftAssignments)
|
||||||
id: true,
|
.omit({
|
||||||
assignedAt: true,
|
id: true,
|
||||||
});
|
assignedAt: true,
|
||||||
|
})
|
||||||
|
.extend({
|
||||||
|
plannedStartTime: z.union([z.string(), z.date()], {
|
||||||
|
required_error: "Orario inizio richiesto",
|
||||||
|
invalid_type_error: "Orario inizio non valido",
|
||||||
|
}).transform((val) => new Date(val)),
|
||||||
|
plannedEndTime: z.union([z.string(), z.date()], {
|
||||||
|
required_error: "Orario fine richiesto",
|
||||||
|
invalid_type_error: "Orario fine non valido",
|
||||||
|
}).transform((val) => new Date(val)),
|
||||||
|
})
|
||||||
|
.refine((data) => data.plannedEndTime > data.plannedStartTime, {
|
||||||
|
message: "L'orario di fine deve essere successivo all'orario di inizio",
|
||||||
|
path: ["plannedEndTime"],
|
||||||
|
});
|
||||||
|
|
||||||
export const insertCcnlSettingSchema = createInsertSchema(ccnlSettings).omit({
|
export const insertCcnlSettingSchema = createInsertSchema(ccnlSettings).omit({
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user