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:
parent
1cdae8c4b3
commit
4a2b5fab66
4
.replit
4
.replit
@ -19,10 +19,6 @@ externalPort = 80
|
|||||||
localPort = 33035
|
localPort = 33035
|
||||||
externalPort = 3001
|
externalPort = 3001
|
||||||
|
|
||||||
[[ports]]
|
|
||||||
localPort = 39567
|
|
||||||
externalPort = 6000
|
|
||||||
|
|
||||||
[[ports]]
|
[[ports]]
|
||||||
localPort = 41295
|
localPort = 41295
|
||||||
externalPort = 5173
|
externalPort = 5173
|
||||||
|
|||||||
@ -241,9 +241,16 @@ export default function PlanningMobile() {
|
|||||||
|
|
||||||
// Mutation per salvare patrol route
|
// Mutation per salvare patrol route
|
||||||
const savePatrolRouteMutation = useMutation({
|
const savePatrolRouteMutation = useMutation({
|
||||||
mutationFn: async (data: any) => {
|
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);
|
const response = await apiRequest("POST", "/api/patrol-routes", data);
|
||||||
return response.json();
|
return response.json();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast({
|
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
|
// Carica patrol route esistente quando si seleziona una guardia
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user