From 9f69fb0a81f7993e9f9cfa763891bb03122df425 Mon Sep 17 00:00:00 2001 From: tamaina Date: Mon, 19 Jul 2021 14:58:18 +0900 Subject: [PATCH] =?UTF-8?q?=E4=BA=92=E6=8F=9B=E6=80=A7=E3=81=A7notificatio?= =?UTF-8?q?nId=E3=82=92=E5=8F=97=E3=81=91=E4=BB=98=E3=81=91=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/endpoints/notifications/read.ts | 34 +++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) 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) +});