mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-06 22:52:06 +00:00
58 lines
1.8 KiB
TypeScript
58 lines
1.8 KiB
TypeScript
|
|
import { API_PATHS } from "@/api/api-paths";
|
||
|
|
import { apiGet, apiPost } from "@/api/api";
|
||
|
|
import { handleApiResponse, handlePaginatedResponse } from "@/api/handle-api-response";
|
||
|
|
import {
|
||
|
|
mapPmSchedule,
|
||
|
|
mapPmScheduleListItem,
|
||
|
|
mapPmScheduleToSavePayload,
|
||
|
|
} from "@/domain/pm-schedules/mappers/pm-schedule-mapper";
|
||
|
|
import type {
|
||
|
|
PmSchedule,
|
||
|
|
PmSchedulesListParams,
|
||
|
|
PmSchedulesListResult,
|
||
|
|
} from "@/domain/pm-schedules/types/pm-schedule";
|
||
|
|
|
||
|
|
export const pmSchedulesApi = {
|
||
|
|
getList: async (params: PmSchedulesListParams = {}): Promise<PmSchedulesListResult> => {
|
||
|
|
const data = await apiGet<unknown>(API_PATHS.pmSchedule.getList, {
|
||
|
|
searchParams: {
|
||
|
|
search: params.search ?? "",
|
||
|
|
page: params.page ?? 1,
|
||
|
|
pageSize: params.pageSize ?? 12,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
const paginated = handlePaginatedResponse<unknown>(data, {
|
||
|
|
page: params.page,
|
||
|
|
pageSize: params.pageSize,
|
||
|
|
});
|
||
|
|
|
||
|
|
return {
|
||
|
|
items: paginated.items.map(mapPmScheduleListItem),
|
||
|
|
totalCount: paginated.totalCount,
|
||
|
|
page: paginated.page,
|
||
|
|
pageSize: paginated.pageSize,
|
||
|
|
};
|
||
|
|
},
|
||
|
|
|
||
|
|
getById: async (id: string | number): Promise<PmSchedule> => {
|
||
|
|
const data = await apiGet<unknown>(API_PATHS.pmSchedule.getById, {
|
||
|
|
searchParams: { id },
|
||
|
|
});
|
||
|
|
return mapPmSchedule(handleApiResponse(data));
|
||
|
|
},
|
||
|
|
|
||
|
|
/** 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));
|
||
|
|
},
|
||
|
|
|
||
|
|
delete: async (id: string | number): Promise<void> => {
|
||
|
|
await apiPost<unknown>(API_PATHS.pmSchedule.delete, undefined, {
|
||
|
|
searchParams: { id },
|
||
|
|
});
|
||
|
|
},
|
||
|
|
};
|