-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
panels.ts
60 lines (55 loc) · 1.67 KB
/
panels.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
import type { DirectusPanel } from '../../../schema/panel.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import { throwIfEmpty } from '../../utils/index.js';
import type { RestCommand } from '../../types.js';
export type UpdatePanelOutput<
Schema extends object,
TQuery extends Query<Schema, Item>,
Item extends object = DirectusPanel<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;
/**
* Update multiple existing panels.
* @param keys
* @param item
* @param query
* @returns Returns the panel objects for the updated panels.
* @throws Will throw if keys is empty
*/
export const updatePanels =
<Schema extends object, const TQuery extends Query<Schema, DirectusPanel<Schema>>>(
keys: DirectusPanel<Schema>['id'][],
item: Partial<DirectusPanel<Schema>>,
query?: TQuery,
): RestCommand<UpdatePanelOutput<Schema, TQuery>[], Schema> =>
() => {
throwIfEmpty(keys, 'Keys cannot be empty');
return {
path: `/panels`,
params: query ?? {},
body: JSON.stringify({ keys, data: item }),
method: 'PATCH',
};
};
/**
* Update an existing panel.
* @param key
* @param item
* @param query
* @returns Returns the panel object for the updated panel.
* @throws Will throw if key is empty
*/
export const updatePanel =
<Schema extends object, const TQuery extends Query<Schema, DirectusPanel<Schema>>>(
key: DirectusPanel<Schema>['id'],
item: Partial<DirectusPanel<Schema>>,
query?: TQuery,
): RestCommand<UpdatePanelOutput<Schema, TQuery>, Schema> =>
() => {
throwIfEmpty(key, 'Key cannot be empty');
return {
path: `/panels/${key}`,
params: query ?? {},
body: JSON.stringify(item),
method: 'PATCH',
};
};