yumechi-no-kuni/src/server/api/endpoints/notifications/mark_as_read_all.ts

33 lines
608 B
TypeScript
Raw Normal View History

/**
* Module dependencies
*/
2018-03-29 06:32:18 -05:00
import Notification from '../../../../models/notification';
2018-04-01 22:58:53 -05:00
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 00:48:47 -05:00
notifieeId: user._id,
isRead: false
}, {
$set: {
2018-03-29 00:48:47 -05:00
isRead: true
}
}, {
multi: true
});
// Response
res();
// 全ての通知を読みましたよというイベントを発行
event(user._id, 'read_all_notifications');
});