From 4a2b5fab66e760175f7609180824ca0ac4f08d5a Mon Sep 17 00:00:00 2001 From: marco370 <48531002-marco370@users.noreply.replit.com> Date: Thu, 23 Oct 2025 16:09:30 +0000 Subject: [PATCH] Update patrol route saving to handle existing routes correctly Modify the `savePatrolRouteMutation` in `planning-mobile.tsx` to use PUT for updating existing patrol routes and POST for creating new ones, addressing a 400 error when modifying patrol sequences. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e5565357-90e1-419f-b9a8-6ee8394636df Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/6d543d2c-20b9-4ea6-93fe-70fe9b1d9f80/e5565357-90e1-419f-b9a8-6ee8394636df/kDVJJUd --- .replit | 4 ---- client/src/pages/planning-mobile.tsx | 23 +++++++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) 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