mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 14:42:05 +00:00
fix(pm-schedules): handle empty save and delete responses
This commit is contained in:
parent
42a8c752cc
commit
6beba0ba93
1 changed files with 17 additions and 4 deletions
|
|
@ -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 },
|
||||
});
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue