monkeeShark/src/server/api/endpoints/notifications/mark_all_as_read.ts
syuilo 2756f553c6
Improve error handling of API (#4345)
* wip

* wip

* wip

* Update attached_notes.ts

* wip

* Refactor

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Update call.ts

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* ✌️

* Fix
2019-02-22 11:46:58 +09:00

39 lines
832 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.'
},
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');
});