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
This commit is contained in:
marco370 2025-10-23 16:09:30 +00:00
parent 1cdae8c4b3
commit 4a2b5fab66
2 changed files with 19 additions and 8 deletions

View File

@ -19,10 +19,6 @@ externalPort = 80
localPort = 33035
externalPort = 3001
[[ports]]
localPort = 39567
externalPort = 6000
[[ports]]
localPort = 41295
externalPort = 5173

View File

@ -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