/
role.ts
65 lines (59 loc) · 1.98 KB
/
role.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { AxiosInstance } from 'contentful-sdk-core'
import copy from 'fast-copy'
import { CollectionProp, GetSpaceParams, QueryParams } from '../../../common-types'
import { CreateRoleProps, RoleProps } from '../../../entities/role'
import { RestEndpoint } from '../types'
import * as raw from './raw'
import { normalizeSelect } from './utils'
export const get: RestEndpoint<'Role', 'get'> = (
http: AxiosInstance,
params: GetSpaceParams & { roleId: string }
) => {
return raw.get<RoleProps>(http, `/spaces/${params.spaceId}/roles/${params.roleId}`)
}
export const getMany: RestEndpoint<'Role', 'getMany'> = (
http: AxiosInstance,
params: GetSpaceParams & QueryParams
) => {
return raw.get<CollectionProp<RoleProps>>(http, `/spaces/${params.spaceId}/roles`, {
params: normalizeSelect(params.query),
})
}
export const create: RestEndpoint<'Role', 'create'> = (
http: AxiosInstance,
params: GetSpaceParams,
data: CreateRoleProps,
headers?: Record<string, unknown>
) => {
return raw.post<RoleProps>(http, `/spaces/${params.spaceId}/roles`, data, {
headers,
})
}
export const createWithId: RestEndpoint<'Role', 'createWithId'> = (
http: AxiosInstance,
params: GetSpaceParams & { roleId: string },
data: CreateRoleProps,
headers?: Record<string, unknown>
) => {
return raw.put<RoleProps>(http, `/spaces/${params.spaceId}/roles/${params.roleId}`, data, {
headers,
})
}
export const update: RestEndpoint<'Role', 'update'> = (
http: AxiosInstance,
params: GetSpaceParams & { roleId: string },
rawData: RoleProps,
headers?: Record<string, unknown>
) => {
const data = copy(rawData)
delete data.sys
return raw.put<RoleProps>(http, `/spaces/${params.spaceId}/roles/${params.roleId}`, data, {
headers: {
...headers,
'X-Contentful-Version': rawData.sys.version ?? 0,
},
})
}
export const del = (http: AxiosInstance, params: GetSpaceParams & { roleId: string }) => {
return raw.del(http, `/spaces/${params.spaceId}/roles/${params.roleId}`)
}