mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-01 07:23:11 +00:00
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
import { apiGet, apiPost, apiPut } from "@/api/api";
|
|
import { API_PATHS } from "@/api/api-paths";
|
|
import { handleApiResponse } from "@/api/handle-api-response";
|
|
import { mapService, mapServices } from "@/domain/services/mappers/service-mapper";
|
|
import type { Service, ServiceInput } from "@/domain/services/types/service";
|
|
|
|
export const servicesApi = {
|
|
getAll: async (isActive?: boolean): Promise<Service[]> => {
|
|
const data = await apiGet<unknown>(API_PATHS.services.list, {
|
|
searchParams: isActive === undefined ? undefined : { isActive },
|
|
});
|
|
return mapServices(handleApiResponse(data));
|
|
},
|
|
|
|
create: async (input: ServiceInput): Promise<Service> => {
|
|
const data = await apiPost<unknown>(API_PATHS.services.list, input);
|
|
return mapService(handleApiResponse(data));
|
|
},
|
|
|
|
update: async (id: string | number, input: ServiceInput): Promise<Service> => {
|
|
const data = await apiPut<unknown>(API_PATHS.services.byId(id), input);
|
|
return mapService(handleApiResponse(data));
|
|
},
|
|
|
|
deactivate: async (id: string | number): Promise<void> => {
|
|
await apiPost(API_PATHS.services.deactivate(id));
|
|
},
|
|
};
|