summaryrefslogtreecommitdiff
path: root/packages/backend/src/server/api/endpoints/notifications/create.ts
blob: bd8a7ba1b7c3317a4c2bd7378a8d5ba0dbf82867 (plain)
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
import $ from 'cafy';
import define from '../../define';
import { createNotification } from '@/services/create-notification';

export const meta = {
	tags: ['notifications'],

	requireCredential: true,

	kind: 'write:notifications',

	params: {
		body: {
			validator: $.str,
		},

		header: {
			validator: $.optional.nullable.str,
		},

		icon: {
			validator: $.optional.nullable.str,
		},
	},

	errors: {
	},
} as const;

// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, user, token) => {
	createNotification(user.id, 'app', {
		appAccessTokenId: token ? token.id : null,
		customBody: ps.body,
		customHeader: ps.header,
		customIcon: ps.icon,
	});
});