monkeeShark/src/server/api/endpoints/notifications/mark_all_as_read.ts
syuilo 52774bbe64
Introduce OpenAPI specs (#4351)
* wip

* wip

* wip

* Update index.ts

* Update gen-openapi-spec.ts

* Update api.ja-JP.md

* Fix

* Improve doc

* Update gen-openapi-spec.ts

* Update redoc.html

* Improve doc

* Update gen-openapi-spec.ts

* Improve doc

* Update CHANGELOG.md
2019-02-23 11:20:58 +09:00

41 lines
870 B
TypeScript

import Notification from '../../../../models/notification';
import { publishMainStream } from '../../../../services/stream';
import User from '../../../../models/user';
import define from '../../define';
export const meta = {
desc: {
'ja-JP': '全ての通知を既読にします。',
'en-US': 'Mark all notifications as read.'
},
tags: ['notifications', 'account'],
requireCredential: true,
kind: 'notification-write'
};
export default define(meta, async (ps, user) => {
// Update documents
await Notification.update({
notifieeId: user._id,
isRead: false
}, {
$set: {
isRead: true
}
}, {
multi: true
});
// Update flag
User.update({ _id: user._id }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての通知を読みましたよというイベントを発行
publishMainStream(user._id, 'readAllNotifications');
});