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