-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
activity.ts
35 lines (32 loc) · 1.11 KB
/
activity.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
import type { DirectusActivity } from '../../../schema/activity.js';
import type { ApplyQueryFields, Query } from '../../../types/index.js';
import { throwIfEmpty } from '../../utils/index.js';
import type { RestCommand } from '../../types.js';
export type UpdateActivityOutput<
Schema extends object,
TQuery extends Query<Schema, Item>,
Item extends object = DirectusActivity<Schema>,
> = ApplyQueryFields<Schema, Item, TQuery['fields']>;
/**
* Updates an existing comment by activity action primary key.
* @param key
* @param item
* @param query
* @returns Returns the activity object of the created comment.
* @throws Will throw if key is empty
*/
export const updateComment =
<Schema extends object, const TQuery extends Query<Schema, DirectusActivity<Schema>>>(
key: DirectusActivity<Schema>['id'],
item: Partial<DirectusActivity<Schema>>,
query?: TQuery,
): RestCommand<UpdateActivityOutput<Schema, TQuery>, Schema> =>
() => {
throwIfEmpty(String(key), 'Key cannot be empty');
return {
path: `/activity/comment/${key}`,
params: query ?? {},
body: JSON.stringify(item),
method: 'PATCH',
};
};