-
Notifications
You must be signed in to change notification settings - Fork 97
/
editor-interface.ts
48 lines (43 loc) · 1.43 KB
/
editor-interface.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
import type { AxiosInstance } from 'contentful-sdk-core'
import copy from 'fast-copy'
import {
CollectionProp,
GetEditorInterfaceParams,
GetSpaceEnvironmentParams,
QueryParams,
} from '../../../common-types'
import { EditorInterfaceProps } from '../../../entities/editor-interface'
import { RestEndpoint } from '../types'
import * as raw from './raw'
const getBaseUrl = (params: GetEditorInterfaceParams) =>
`/spaces/${params.spaceId}/environments/${params.environmentId}/content_types/${params.contentTypeId}/editor_interface`
export const get: RestEndpoint<'EditorInterface', 'get'> = (
http: AxiosInstance,
params: GetEditorInterfaceParams
) => {
return raw.get<EditorInterfaceProps>(http, getBaseUrl(params))
}
export const getMany: RestEndpoint<'EditorInterface', 'getMany'> = (
http: AxiosInstance,
params: GetSpaceEnvironmentParams & QueryParams
) => {
return raw.get<CollectionProp<EditorInterfaceProps>>(
http,
`/spaces/${params.spaceId}/environments/${params.environmentId}/editor_interfaces`
)
}
export const update: RestEndpoint<'EditorInterface', 'update'> = (
http: AxiosInstance,
params: GetEditorInterfaceParams,
rawData: EditorInterfaceProps,
headers?: Record<string, unknown>
) => {
const data = copy(rawData)
delete data.sys
return raw.put<EditorInterfaceProps>(http, getBaseUrl(params), data, {
headers: {
'X-Contentful-Version': rawData.sys.version ?? 0,
...headers,
},
})
}