Skip to content
This repository was archived by the owner on Feb 5, 2024. It is now read-only.

Commit 7da5eea

Browse files
committed
1 parent f984f56 commit 7da5eea

File tree

1 file changed

+42
-0
lines changed
  • src/server/api/endpoints/notifications

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import $ from 'cafy';
2+
import { ID } from '@/misc/cafy-id';
3+
import { publishMainStream } from '../../../../services/stream';
4+
import define from '../../define';
5+
import { Notifications } from '../../../../models';
6+
import { readNotification } from '../../common/read-notification';
7+
import { ApiError } from '../../error';
8+
9+
export const meta = {
10+
tags: ['notifications', 'account'],
11+
12+
requireCredential: true as const,
13+
14+
kind: 'write:notifications',
15+
16+
params: {
17+
notificationId: {
18+
validator: $.type(ID),
19+
},
20+
},
21+
22+
errors: {
23+
noSuchNotification: {
24+
message: 'No such notification.',
25+
code: 'NO_SUCH_NOTIFICATION',
26+
id: 'efa929d5-05b5-47d1-beec-e6a4dbed011e'
27+
},
28+
},
29+
};
30+
31+
export default define(meta, async (ps, user) => {
32+
const notification = await Notifications.findOne({
33+
notifieeId: user.id,
34+
id: ps.notificationId,
35+
});
36+
37+
if (notification == null) {
38+
throw new ApiError(meta.errors.noSuchNotification);
39+
}
40+
41+
readNotification(user.id, [notification.id]);
42+
});

0 commit comments

Comments
 (0)