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:
parent
e3ab9e2b83
commit
4092e8c8e9
4
.replit
4
.replit
@ -19,10 +19,6 @@ externalPort = 80
|
||||
localPort = 33035
|
||||
externalPort = 3001
|
||||
|
||||
[[ports]]
|
||||
localPort = 34977
|
||||
externalPort = 4200
|
||||
|
||||
[[ports]]
|
||||
localPort = 41343
|
||||
externalPort = 3000
|
||||
|
||||
@ -57,7 +57,7 @@ export default function OperationalPlanning() {
|
||||
);
|
||||
|
||||
const { data, isLoading, refetch } = useQuery<AvailabilityData>({
|
||||
queryKey: ["/api/operational-planning/availability", selectedDate],
|
||||
queryKey: [`/api/operational-planning/availability?date=${selectedDate}`, selectedDate],
|
||||
enabled: !!selectedDate,
|
||||
});
|
||||
|
||||
|
||||
@ -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<Server> {
|
||||
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<Server> {
|
||||
});
|
||||
|
||||
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) });
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user