2017-10-30 08:12:10 -05:00
|
|
|
/**
|
|
|
|
* Module dependencies
|
|
|
|
*/
|
2018-03-29 06:32:18 -05:00
|
|
|
import Notification from '../../../../models/notification';
|
2018-04-01 23:33:46 -05:00
|
|
|
import event from '../../../../publishers/stream';
|
2017-10-30 08:12:10 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark as read all notifications
|
|
|
|
*/
|
|
|
|
module.exports = (params, user) => new Promise(async (res, rej) => {
|
|
|
|
// Update documents
|
|
|
|
await Notification.update({
|
2018-03-29 00:48:47 -05:00
|
|
|
notifieeId: user._id,
|
|
|
|
isRead: false
|
2017-10-30 08:12:10 -05:00
|
|
|
}, {
|
|
|
|
$set: {
|
2018-03-29 00:48:47 -05:00
|
|
|
isRead: true
|
2017-10-30 08:12:10 -05:00
|
|
|
}
|
|
|
|
}, {
|
|
|
|
multi: true
|
|
|
|
});
|
|
|
|
|
|
|
|
// Response
|
|
|
|
res();
|
|
|
|
|
|
|
|
// 全ての通知を読みましたよというイベントを発行
|
|
|
|
event(user._id, 'read_all_notifications');
|
|
|
|
});
|