diff --git a/.replit b/.replit index e6d5f41..75d108a 100644 --- a/.replit +++ b/.replit @@ -19,10 +19,6 @@ externalPort = 80 localPort = 33035 externalPort = 3001 -[[ports]] -localPort = 39567 -externalPort = 6000 - [[ports]] localPort = 41295 externalPort = 5173 diff --git a/client/src/pages/planning-mobile.tsx b/client/src/pages/planning-mobile.tsx index fac3fd3..851336a 100644 --- a/client/src/pages/planning-mobile.tsx +++ b/client/src/pages/planning-mobile.tsx @@ -241,9 +241,16 @@ export default function PlanningMobile() { // Mutation per salvare patrol route const savePatrolRouteMutation = useMutation({ - mutationFn: async (data: any) => { - const response = await apiRequest("POST", "/api/patrol-routes", data); - return response.json(); + mutationFn: async ({ data, existingRouteId }: { data: any; existingRouteId?: string }) => { + if (existingRouteId) { + // UPDATE: usa PUT se esiste già un patrol route + const response = await apiRequest("PUT", `/api/patrol-routes/${existingRouteId}`, data); + return response.json(); + } else { + // CREATE: usa POST se è un nuovo patrol route + const response = await apiRequest("POST", "/api/patrol-routes", data); + return response.json(); + } }, onSuccess: () => { toast({ @@ -295,7 +302,15 @@ export default function PlanningMobile() { })), }; - savePatrolRouteMutation.mutate(patrolRouteData); + // Controlla se esiste già un patrol route per questa guardia/data + const existingRoute = existingPatrolRoutes?.find( + (route: any) => route.guardId === selectedGuard.id + ); + + savePatrolRouteMutation.mutate({ + data: patrolRouteData, + existingRouteId: existingRoute?.id, + }); }; // Carica patrol route esistente quando si seleziona una guardia