fix(pm-schedules): handle empty save and delete responses

This commit is contained in:
Arthur Bassi 2026-06-16 09:11:58 -03:00
parent 42a8c752cc
commit 6beba0ba93

View file

@ -1,5 +1,5 @@
import { API_PATHS } from "@/api/api-paths";
import { apiGet, apiPost } from "@/api/api";
import { apiGet, apiPostNoContent } from "@/api/api";
import { handleApiResponse, handlePaginatedResponse } from "@/api/handle-api-response";
import {
mapPmSchedule,
@ -45,12 +45,25 @@ export const pmSchedulesApi = {
/** Create and update both use PMSchedule/Save — Id=0 for create. */
save: async (schedule: Partial<PmSchedule> & { id?: number }): Promise<PmSchedule> => {
const payload = mapPmScheduleToSavePayload(schedule);
const data = await apiPost<unknown>(API_PATHS.pmSchedule.save, payload);
return mapPmSchedule(handleApiResponse(data));
await apiPostNoContent(API_PATHS.pmSchedule.save, payload);
if (schedule.id && schedule.id > 0) {
return pmSchedulesApi.getById(schedule.id);
}
return mapPmSchedule({
Id: 0,
Name: payload.Name,
Frequency: payload.Frequency,
StartDate: payload.StartDate,
IsActive: payload.IsActive,
AssetId: payload.AssetId,
LocationId: payload.LocationId,
});
},
delete: async (id: string | number): Promise<void> => {
await apiPost<unknown>(API_PATHS.pmSchedule.delete, undefined, {
await apiPostNoContent(API_PATHS.pmSchedule.delete, undefined, {
searchParams: { id },
});
},