mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-08 01:55:41 +00:00
65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { api as apiClient } from "../auth/http";
|
|
|
|
// NOTE: `auth/http`'s response interceptor already unwraps the API's
|
|
// `{ success, data }` envelope, so `response.data` IS the payload here — a
|
|
// second `.data` hop reads undefined and silently yields an empty list.
|
|
|
|
/** A desk mapped to a yard, joined to its IAM position for display. */
|
|
export interface YardPositionRow {
|
|
id: string;
|
|
yardId: string;
|
|
yardCode: string;
|
|
yardLabel: string;
|
|
positionId: string;
|
|
positionName: { am?: string; en?: string } | null;
|
|
positionTypeKey: string | null;
|
|
}
|
|
|
|
export interface SelectablePosition {
|
|
id: string;
|
|
name: { am?: string; en?: string } | null;
|
|
positionTypeKey: string | null;
|
|
unitKey: string | null;
|
|
}
|
|
|
|
export interface MyYardScope {
|
|
/** null = unrestricted (super admin or `yards:view_all`). */
|
|
yardIds: string[] | null;
|
|
unrestricted: boolean;
|
|
/** False while the backend is still shadow-logging instead of denying. */
|
|
enforced: boolean;
|
|
}
|
|
|
|
export const yardPositionsService = {
|
|
listByYard: async (yardId: string): Promise<YardPositionRow[]> => {
|
|
const { data } = await apiClient.get(`/yard-positions`, {
|
|
params: { yardId },
|
|
});
|
|
return data ?? [];
|
|
},
|
|
|
|
listPositions: async (): Promise<SelectablePosition[]> => {
|
|
const { data } = await apiClient.get(`/yard-positions/positions`);
|
|
return data ?? [];
|
|
},
|
|
|
|
myScope: async (): Promise<MyYardScope> => {
|
|
const { data } = await apiClient.get(`/yard-positions/my-yards`);
|
|
return data;
|
|
},
|
|
|
|
/**
|
|
* Replaces the yard's whole desk set — send every position that should remain
|
|
* mapped, not just the additions.
|
|
*/
|
|
setForYard: async (
|
|
yardId: string,
|
|
positionIds: string[],
|
|
): Promise<YardPositionRow[]> => {
|
|
const { data } = await apiClient.put(`/yard-positions/yard/${yardId}`, {
|
|
positionIds,
|
|
});
|
|
return data ?? [];
|
|
},
|
|
};
|