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

34 lines
695 B
TypeScript
Raw Normal View History

2018-03-29 11:32:18 +00:00
import Notification from '../../../../models/notification';
2018-04-02 04:33:46 +00:00
import event from '../../../../publishers/stream';
2018-06-18 00:54:53 +00:00
import User, { ILocalUser } from '../../../../models/user';
/**
* Mark as read all notifications
*/
2018-06-18 00:54:53 +00:00
module.exports = (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
// Update documents
await Notification.update({
2018-03-29 05:48:47 +00:00
notifieeId: user._id,
isRead: false
}, {
$set: {
2018-03-29 05:48:47 +00:00
isRead: true
}
}, {
multi: true
});
// Response
res();
2018-05-28 16:22:39 +00:00
// Update flag
User.update({ _id: user._id }, {
$set: {
hasUnreadNotification: false
}
});
// 全ての通知を読みましたよというイベントを発行
event(user._id, 'read_all_notifications');
});