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
This commit is contained in:
marco370 2025-10-17 10:51:36 +00:00
parent e3ab9e2b83
commit 4092e8c8e9
3 changed files with 9 additions and 14 deletions

View File

@ -19,10 +19,6 @@ externalPort = 80
localPort = 33035 localPort = 33035
externalPort = 3001 externalPort = 3001
[[ports]]
localPort = 34977
externalPort = 4200
[[ports]] [[ports]]
localPort = 41343 localPort = 41343
externalPort = 3000 externalPort = 3000

View File

@ -57,7 +57,7 @@ export default function OperationalPlanning() {
); );
const { data, isLoading, refetch } = useQuery<AvailabilityData>({ const { data, isLoading, refetch } = useQuery<AvailabilityData>({
queryKey: ["/api/operational-planning/availability", selectedDate], queryKey: [`/api/operational-planning/availability?date=${selectedDate}`, selectedDate],
enabled: !!selectedDate, enabled: !!selectedDate,
}); });

View File

@ -6,7 +6,7 @@ import { setupLocalAuth, isAuthenticated as isAuthenticatedLocal } from "./local
import { db } from "./db"; import { db } from "./db";
import { guards, certifications, sites, shifts, shiftAssignments, users, insertShiftSchema, contractParameters } from "@shared/schema"; import { guards, certifications, sites, shifts, shiftAssignments, users, insertShiftSchema, contractParameters } from "@shared/schema";
import { eq, and, gte, lte, desc, asc } from "drizzle-orm"; 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 // Determina quale sistema auth usare basandosi sull'ambiente
const USE_LOCAL_AUTH = process.env.DOMAIN === "vt.alfacom.it" || !process.env.REPLIT_DOMAINS; 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<Server> {
app.get("/api/operational-planning/availability", isAuthenticated, async (req, res) => { app.get("/api/operational-planning/availability", isAuthenticated, async (req, res) => {
try { try {
const { getGuardAvailabilityReport } = await import("./ccnlRules"); 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 // Imposta inizio e fine giornata in UTC
const startOfDay = new Date(date); const startOfDay = new Date(dateStr + "T00:00:00.000Z");
startOfDay.setHours(0, 0, 0, 0); const endOfDay = new Date(dateStr + "T23:59:59.999Z");
const endOfDay = new Date(date);
endOfDay.setHours(23, 59, 59, 999);
// Ottieni tutti i veicoli // Ottieni tutti i veicoli
const allVehicles = await storage.getAllVehicles(); const allVehicles = await storage.getAllVehicles();
@ -645,13 +644,13 @@ export async function registerRoutes(app: Express): Promise<Server> {
}); });
res.json({ res.json({
date: date.toISOString(), date: dateStr,
vehicles: sortedVehicles, vehicles: sortedVehicles,
guards: sortedGuards guards: sortedGuards
}); });
} catch (error) { } catch (error) {
console.error("Error fetching operational planning availability:", 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) });
} }
}); });