From 4092e8c8e9a4da56e43ec9fd7ed3ec8d4eaaad4f Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Fri, 17 Oct 2025 10:51:36 +0000 Subject: [PATCH] Update operational planning to display correct daily availability Refactors date handling for operational planning API to use ISO strings and UTC, improving accuracy and consistency. 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/sshIJbn --- .replit | 4 ---- client/src/pages/operational-planning.tsx | 2 +- server/routes.ts | 17 ++++++++--------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.replit b/.replit index 523fe88..c50bc15 100644 --- a/.replit +++ b/.replit @@ -19,10 +19,6 @@ externalPort = 80 localPort = 33035 externalPort = 3001 -[[ports]] -localPort = 34977 -externalPort = 4200 - [[ports]] localPort = 41343 externalPort = 3000 diff --git a/client/src/pages/operational-planning.tsx b/client/src/pages/operational-planning.tsx index 2359b27..5215b4e 100644 --- a/client/src/pages/operational-planning.tsx +++ b/client/src/pages/operational-planning.tsx @@ -57,7 +57,7 @@ export default function OperationalPlanning() { ); const { data, isLoading, refetch } = useQuery({ - queryKey: ["/api/operational-planning/availability", selectedDate], + queryKey: [`/api/operational-planning/availability?date=${selectedDate}`, selectedDate], enabled: !!selectedDate, }); diff --git a/server/routes.ts b/server/routes.ts index 3f40072..aca930a 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -6,7 +6,7 @@ import { setupLocalAuth, isAuthenticated as isAuthenticatedLocal } from "./local import { db } from "./db"; import { guards, certifications, sites, shifts, shiftAssignments, users, insertShiftSchema, contractParameters } from "@shared/schema"; import { eq, and, gte, lte, desc, asc } from "drizzle-orm"; -import { differenceInDays, differenceInHours, differenceInMinutes, startOfWeek, endOfWeek, startOfMonth, endOfMonth, isWithinInterval, startOfDay, isSameDay, parseISO } from "date-fns"; +import { differenceInDays, differenceInHours, differenceInMinutes, startOfWeek, endOfWeek, startOfMonth, endOfMonth, isWithinInterval, startOfDay, isSameDay, parseISO, format } from "date-fns"; // Determina quale sistema auth usare basandosi sull'ambiente const USE_LOCAL_AUTH = process.env.DOMAIN === "vt.alfacom.it" || !process.env.REPLIT_DOMAINS; @@ -538,13 +538,12 @@ export async function registerRoutes(app: Express): Promise { app.get("/api/operational-planning/availability", isAuthenticated, async (req, res) => { try { const { getGuardAvailabilityReport } = await import("./ccnlRules"); - const date = req.query.date ? new Date(req.query.date as string) : new Date(); + const dateStr = req.query.date as string || format(new Date(), "yyyy-MM-dd"); + const date = new Date(dateStr + "T00:00:00.000Z"); - // Imposta inizio e fine giornata - const startOfDay = new Date(date); - startOfDay.setHours(0, 0, 0, 0); - const endOfDay = new Date(date); - endOfDay.setHours(23, 59, 59, 999); + // Imposta inizio e fine giornata in UTC + const startOfDay = new Date(dateStr + "T00:00:00.000Z"); + const endOfDay = new Date(dateStr + "T23:59:59.999Z"); // Ottieni tutti i veicoli const allVehicles = await storage.getAllVehicles(); @@ -645,13 +644,13 @@ export async function registerRoutes(app: Express): Promise { }); res.json({ - date: date.toISOString(), + date: dateStr, vehicles: sortedVehicles, guards: sortedGuards }); } catch (error) { console.error("Error fetching operational planning availability:", error); - res.status(500).json({ message: "Failed to fetch availability" }); + res.status(500).json({ message: "Failed to fetch availability", error: String(error) }); } });