forked from openedx/frontend-app-admin-console
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.ts
More file actions
39 lines (34 loc) · 1.35 KB
/
api.ts
File metadata and controls
39 lines (34 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth';
import { LibraryMetadata, TeamMember } from '@src/types';
import { camelCaseObject } from '@edx/frontend-platform';
import { getApiUrl, getStudioApiUrl } from '@src/data/utils';
export interface GetTeamMembersResponse {
members: TeamMember[];
totalCount: number;
}
export type PermissionsByRole = {
role: string;
permissions: string[];
userCount: number;
};
// TODO: replece api path once is created
export const getTeamMembers = async (object: string): Promise<TeamMember[]> => {
const { data } = await getAuthenticatedHttpClient().get(getApiUrl(`/api/authz/v1/roles/users/?scope=${object}`));
return camelCaseObject(data.results);
};
// TODO: this should be replaced in the future with Console API
export const getLibrary = async (libraryId: string): Promise<LibraryMetadata> => {
const { data } = await getAuthenticatedHttpClient().get(getStudioApiUrl(`/api/libraries/v2/${libraryId}/`));
return {
id: data.id,
org: data.org,
title: data.title,
slug: data.slug,
};
};
export const getPermissionsByRole = async (scope: string): Promise<PermissionsByRole[]> => {
const url = new URL(getApiUrl('/api/authz/v1/roles/'));
url.searchParams.append('scope', scope);
const { data } = await getAuthenticatedHttpClient().get(url);
return camelCaseObject(data.results);
};