Merge branch 'notification-read-api' into sw-notification-action

This commit is contained in:
tamaina 2021-07-19 14:58:39 +09:00
commit effecacf50

View file

@ -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)
});