Files
edr-platform/apps/edr-freight-web/backoffice/src/user-management/services/api/locationService.ts
2026-08-18 12:55:11 +00:00

56 lines
1.8 KiB
TypeScript

import { withHeaders } from "@/record-management/services/api/withHeaders";
import axiosInstance from "@/shared/services/axiosInstance";
import type {
ListQuery,
ListResponse,
Location,
LocationPayload,
LocationType,
LocationTypePayload,
} from "@/user-management/dto/locations/location.type";
import { AxiosResponse } from "axios";
export const locationService = {
list: (
params: ListQuery = {},
): Promise<AxiosResponse<ListResponse<Location>>> =>
axiosInstance.get(`/locations`, { params, headers: withHeaders() }),
create: (payload: LocationPayload): Promise<AxiosResponse<Location>> =>
axiosInstance.post(`/locations`, payload, { headers: withHeaders() }),
update: (
id: string,
payload: LocationPayload,
): Promise<AxiosResponse<Location>> =>
axiosInstance.put(`/locations/${id}`, payload, { headers: withHeaders() }),
// Hard delete server-side — a location with children or unit clusters fails
// on the foreign key rather than returning a tidy 409.
remove: (id: string): Promise<AxiosResponse<void>> =>
axiosInstance.delete(`/locations/${id}`, { headers: withHeaders() }),
};
export const locationTypeService = {
list: (
params: ListQuery = {},
): Promise<AxiosResponse<ListResponse<LocationType>>> =>
axiosInstance.get(`/location-types`, { params, headers: withHeaders() }),
create: (
payload: LocationTypePayload,
): Promise<AxiosResponse<LocationType>> =>
axiosInstance.post(`/location-types`, payload, { headers: withHeaders() }),
update: (
id: string,
payload: LocationTypePayload,
): Promise<AxiosResponse<LocationType>> =>
axiosInstance.put(`/location-types/${id}`, payload, {
headers: withHeaders(),
}),
remove: (id: string): Promise<AxiosResponse<void>> =>
axiosInstance.delete(`/location-types/${id}`, { headers: withHeaders() }),
};