PermissionService.ts 1.17 KB
Newer Older
Maxym Borodenko's avatar
Maxym Borodenko committed
1
import {AclObjectIdentity, SidPermissions} from 'model/acl.model';
2
import { axiosBackend } from 'utilities/requestUtils';
3
import {APIv1_BASE_URL} from 'constants/apiURLS';
Maxym Borodenko's avatar
Maxym Borodenko committed
4
5
// import {log} from 'utilities/debug';

6
const API_URL = `${APIv1_BASE_URL}/permission`;
Maxym Borodenko's avatar
Maxym Borodenko committed
7
8
9

export class PermissionService {

10
    public static permissions(clazz: string, id: number): Promise<AclObjectIdentity> {
Maxym Borodenko's avatar
Maxym Borodenko committed
11

12
        return axiosBackend.request({
Maxym Borodenko's avatar
Maxym Borodenko committed
13
14
15
16
17
            url: `${API_URL}/permissions/${clazz}/${id}`,
            method: 'GET',
        }).then(({data}) => new AclObjectIdentity(data));
    }

18
    public static addPermission(clazz: string, id: number, sidPermissions: SidPermissions): Promise<AclObjectIdentity> {
Maxym Borodenko's avatar
Maxym Borodenko committed
19

20
        return axiosBackend.request({
Maxym Borodenko's avatar
Maxym Borodenko committed
21
22
23
24
25
26
27
28
            url: `${API_URL}/permissions/${clazz}/${id}`,
            method: 'POST',
            data: {
                ...sidPermissions,
            },
        }).then(({data}) => new AclObjectIdentity(data));
    }

29
    public static autocomplete(term: string): Promise<{[key: string]: number}> {
Maxym Borodenko's avatar
Maxym Borodenko committed
30

31
        return axiosBackend.request({
Maxym Borodenko's avatar
Maxym Borodenko committed
32
33
34
35
36
37
            url: `${API_URL}/autocomplete?term=${term}`,
            method: 'GET',
        }).then(({data}) => data);
    }

}