forked from FoundKeyGang/FoundKey
Clean up
This commit is contained in:
parent
d731acfd8e
commit
85b8625e29
1 changed files with 29 additions and 30 deletions
|
@ -16,39 +16,38 @@ import event from '../../../event';
|
||||||
* @return {Promise<object>}
|
* @return {Promise<object>}
|
||||||
*/
|
*/
|
||||||
module.exports = (params, user) =>
|
module.exports = (params, user) =>
|
||||||
new Promise(async (res, rej) =>
|
new Promise(async (res, rej) => {
|
||||||
{
|
const notificationId = params.notification;
|
||||||
const notificationId = params.notification;
|
|
||||||
|
|
||||||
if (notificationId === undefined || notificationId === null) {
|
if (notificationId === undefined || notificationId === null) {
|
||||||
return rej('notification is required');
|
return rej('notification is required');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get notifcation
|
// Get notifcation
|
||||||
const notification = await Notification
|
const notification = await Notification
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: new mongo.ObjectID(notificationId),
|
_id: new mongo.ObjectID(notificationId),
|
||||||
i: user._id
|
i: user._id
|
||||||
|
});
|
||||||
|
|
||||||
|
if (notification === null) {
|
||||||
|
return rej('notification-not-found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update
|
||||||
|
notification.is_read = true;
|
||||||
|
Notification.update({ _id: notification._id }, {
|
||||||
|
$set: {
|
||||||
|
is_read: true
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (notification === null) {
|
// Response
|
||||||
return rej('notification-not-found');
|
res();
|
||||||
}
|
|
||||||
|
|
||||||
// Update
|
// Serialize
|
||||||
notification.is_read = true;
|
const notificationObj = await serialize(notification);
|
||||||
Notification.update({ _id: notification._id }, {
|
|
||||||
$set: {
|
// Publish read_notification event
|
||||||
is_read: true
|
event(user._id, 'read_notification', notificationObj);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Response
|
|
||||||
res();
|
|
||||||
|
|
||||||
// Serialize
|
|
||||||
const notificationObj = await serialize(notification);
|
|
||||||
|
|
||||||
// Publish read_notification event
|
|
||||||
event(user._id, 'read_notification', notificationObj);
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in a new issue