mizzkey/src/server/api/endpoints/notifications/get_unread_count.ts

29 lines
527 B
TypeScript
Raw Normal View History

/**
* Module dependencies
*/
2018-03-29 20:32:18 +09:00
import Notification from '../../../../models/notification';
import Mute from '../../../../models/mute';
/**
* Get count of unread notifications
*/
module.exports = (params, user) => new Promise(async (res, rej) => {
2017-12-22 07:38:57 +09:00
const mute = await Mute.find({
2018-05-22 11:45:49 +09:00
muterId: user._id
2017-12-22 07:38:57 +09:00
});
2018-03-29 14:48:47 +09:00
const mutedUserIds = mute.map(m => m.muteeId);
2017-12-22 07:38:57 +09:00
const count = await Notification
.count({
2018-03-29 14:48:47 +09:00
notifieeId: user._id,
notifierId: {
2017-12-22 07:38:57 +09:00
$nin: mutedUserIds
},
2018-03-29 14:48:47 +09:00
isRead: false
});
res({
count: count
});
});