/
Users.ts
50 lines (43 loc) · 1.1 KB
/
Users.ts
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
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2018 Cognite AS
import { AxiosResponse } from 'axios';
import { apiUrl, projectUrl, rawGet, rawPost } from './core';
export interface User {
uniqueName: string;
groups?: number[];
id?: number;
isDeleted?: boolean;
deletedTime?: number;
}
interface UserDataResponse {
data: {
items: User[];
};
}
/**
* @hidden
*/
const usersUrl = (): string => `${apiUrl(0.5)}/${projectUrl()}/users`;
export class Users {
public static async create(users: Partial<User>[]): Promise<User[]> {
const body = {
items: users,
};
const url = usersUrl();
const response = (await rawPost(url, { data: body })) as AxiosResponse<
UserDataResponse
>;
return response.data.data.items;
}
public static async delete(userIds: number[]): Promise<void> {
const body = {
items: userIds,
};
const url = `${usersUrl()}/delete`;
await rawPost(url, { data: body });
}
public static async list(): Promise<User[]> {
const url = usersUrl();
const response = (await rawGet(url)) as AxiosResponse<UserDataResponse>;
return response.data.data.items;
}
}