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