diff --git a/src/server/api/endpoints/notifications/read.ts b/src/server/api/endpoints/notifications/read.ts index fc99a91b82..6ad413c049 100644 --- a/src/server/api/endpoints/notifications/read.ts +++ b/src/server/api/endpoints/notifications/read.ts @@ -2,6 +2,7 @@ import $ from 'cafy'; import { ID } from '@/misc/cafy-id'; import define from '../../define'; import { readNotification } from '../../common/read-notification'; +import { ApiError } from '../../error'; export const meta = { desc: { @@ -13,9 +14,19 @@ export const meta = { requireCredential: true as const, + kind: 'write:notifications', + params: { + notificationId: { + validator: $.optional.type(ID), + desc: { + 'ja-JP': '対象の通知のID', + 'en-US': 'Target notification ID.' + } + }, + notificationIds: { - validator: $.arr($.type(ID)), + validator: $.optional.arr($.type(ID)), desc: { 'ja-JP': '対象の通知のIDの配列', 'en-US': 'Target notification IDs.' @@ -23,7 +34,24 @@ export const meta = { } }, - kind: 'write:notifications' + errors: { + noNotificationRequested: { + message: 'You requested no notification.', + code: 'NO_NOTIFICATION_REQUESTED', + id: '1dee2109-b88b-21cf-3935-607dad60f5b0' + }, + }, }; -export default define(meta, async (ps, user) => readNotification(user.id, ps.notificationIds)); +export default define(meta, async (ps, user) => { + let notificationIds = [] as string[]; + + if (ps.notificationId) notificationIds.push(ps.notificationId); + if (ps.notificationIds) notificationIds = notificationIds.concat(ps.notificationIds); + + if (notificationIds.length === 0) { + throw new ApiError(meta.errors.noNotificationRequested); + } + + return readNotification(user.id, notificationIds) +});