sharkey/src/server/api/endpoints/notifications/mark_as_read_all.ts

45 lines
866 B
TypeScript
Raw Normal View History

2018-03-29 20:32:18 +09:00
import Notification from '../../../../models/notification';
2018-07-07 19:19:00 +09:00
import event from '../../../../stream';
2018-06-18 09:54:53 +09:00
import User, { ILocalUser } from '../../../../models/user';
2018-07-17 04:36:44 +09:00
export const meta = {
desc: {
ja: '全ての通知を既読にします。',
en: 'Mark as read all notifications.'
},
requireCredential: true,
kind: 'notification-write'
};
/**
* Mark as read all notifications
*/
2018-07-06 02:58:29 +09:00
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Update documents
await Notification.update({
2018-03-29 14:48:47 +09:00
notifieeId: user._id,
isRead: false
}, {
$set: {
2018-03-29 14:48:47 +09:00
isRead: true
}
}, {
multi: true
});
// Response
res();
2018-05-29 01:22:39 +09:00
// Update flag
User.update({ _id: user._id }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての通知を読みましたよというイベントを発行
event(user._id, 'read_all_notifications');
});