mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 06:40:57 +00:00
64 lines
1.7 KiB
TypeScript
64 lines
1.7 KiB
TypeScript
import { api as client } from "../auth/http";
|
|
|
|
export type TradeDirection = "IMPORT" | "EXPORT" | "DOMESTIC";
|
|
|
|
export const ALL_TRADE_DIRECTIONS: TradeDirection[] = [
|
|
"IMPORT",
|
|
"EXPORT",
|
|
"DOMESTIC",
|
|
];
|
|
|
|
export const TRADE_DIRECTION_LABELS: Record<TradeDirection, string> = {
|
|
IMPORT: "Import",
|
|
EXPORT: "Export",
|
|
DOMESTIC: "Intercity",
|
|
};
|
|
|
|
export interface UserTradeAccessRow {
|
|
userId: string;
|
|
directions: TradeDirection[];
|
|
updatedAt: string;
|
|
}
|
|
|
|
export interface MyTradeAccess {
|
|
restricted: boolean;
|
|
directions: TradeDirection[];
|
|
}
|
|
|
|
export interface StaffUser {
|
|
id: string;
|
|
/** Localized jsonb on iam.users — not a plain string. */
|
|
name: { en?: string; am?: string } | null;
|
|
username: string;
|
|
email: string | null;
|
|
}
|
|
|
|
export const userTradeAccessService = {
|
|
/**
|
|
* Employees to assign scopes to. Served by the freight API rather than IAM's
|
|
* `/users/filter`, which 400s on its own pagination params (its @Query() DTO
|
|
* omits skip/take/orderBy while the global whitelist pipe rejects them).
|
|
*/
|
|
employees: async (): Promise<{ items: StaffUser[] }> =>
|
|
(
|
|
await client.get("/staff/users", {
|
|
params: { userType: "employee", pageSize: 100 },
|
|
})
|
|
).data,
|
|
|
|
/** All configured per-user scopes (admin only). */
|
|
list: async (): Promise<UserTradeAccessRow[]> =>
|
|
(await client.get("/user-trade-access")).data,
|
|
|
|
/** Current user's effective scope. */
|
|
me: async (): Promise<MyTradeAccess> =>
|
|
(await client.get("/user-trade-access/me")).data,
|
|
|
|
/** Set the directions a user may see (admin only). */
|
|
set: async (
|
|
userId: string,
|
|
directions: TradeDirection[],
|
|
): Promise<UserTradeAccessRow> =>
|
|
(await client.put(`/user-trade-access/${userId}`, { directions })).data,
|
|
};
|