mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 22:18:12 +00:00
per-user trade-direction access scope
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
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 const userTradeAccessService = {
|
||||
/** 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,
|
||||
};
|
||||
Reference in New Issue
Block a user