summaryrefslogtreecommitdiff
path: root/src/api/endpoints/notifications/mark_as_read_all.ts
blob: 3550e344c444855e913ee4961473de064ddbc2d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
 * 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({
		notifiee_id: user._id,
		is_read: false
	}, {
		$set: {
			is_read: true
		}
	}, {
		multi: true
	});

	// Response
	res();

	// 全ての通知を読みましたよというイベントを発行
	event(user._id, 'read_all_notifications');
});