35 lines
937 B
TypeScript
35 lines
937 B
TypeScript
import type { AppPermission } from "@/types";
|
|
import { axios, handleApiError } from "..";
|
|
|
|
export type FetchPermissionsResponse = AppPermission[];
|
|
|
|
export const getUserPermissionsApi = async (
|
|
userId: string,
|
|
): Promise<FetchPermissionsResponse> => {
|
|
const response = await axios.get<FetchPermissionsResponse>(
|
|
`/api/v1/admin/permissions/${userId}`,
|
|
);
|
|
|
|
if (response.status !== 200 && response.status !== 201)
|
|
throw await handleApiError(response);
|
|
|
|
return response.data;
|
|
};
|
|
|
|
export type FetchGroupedPermissionsResponse = {
|
|
scope: string;
|
|
permissions: AppPermission[];
|
|
}[];
|
|
|
|
export const getPermissionsApi =
|
|
async (): Promise<FetchGroupedPermissionsResponse> => {
|
|
const response = await axios.get<FetchGroupedPermissionsResponse>(
|
|
"/api/v1/admin/permissions",
|
|
);
|
|
|
|
if (response.status !== 200 && response.status !== 201)
|
|
throw await handleApiError(response);
|
|
|
|
return response.data;
|
|
};
|