diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2017-02-27 16:48:19 +0900 |
|---|---|---|
| committer | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2017-02-27 17:39:24 +0900 |
| commit | 85b8625e29e30b72b3f853fbcb8d8cbe7e638de9 (patch) | |
| tree | 73b777430c6afd33074e9ed1c23b26b3822d0aa8 /src/api/endpoints/notifications | |
| parent | Fix English grammatical error (diff) | |
| download | sharkey-85b8625e29e30b72b3f853fbcb8d8cbe7e638de9.tar.gz sharkey-85b8625e29e30b72b3f853fbcb8d8cbe7e638de9.tar.bz2 sharkey-85b8625e29e30b72b3f853fbcb8d8cbe7e638de9.zip | |
Clean up
Diffstat (limited to 'src/api/endpoints/notifications')
| -rw-r--r-- | src/api/endpoints/notifications/mark_as_read.js | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/api/endpoints/notifications/mark_as_read.js b/src/api/endpoints/notifications/mark_as_read.js index 855596a865..c8783c1b57 100644 --- a/src/api/endpoints/notifications/mark_as_read.js +++ b/src/api/endpoints/notifications/mark_as_read.js @@ -16,39 +16,38 @@ import event from '../../../event'; * @return {Promise<object>} */ module.exports = (params, user) => - new Promise(async (res, rej) => -{ - const notificationId = params.notification; + new Promise(async (res, rej) => { + const notificationId = params.notification; - if (notificationId === undefined || notificationId === null) { - return rej('notification is required'); - } - - // Get notifcation - const notification = await Notification - .findOne({ - _id: new mongo.ObjectID(notificationId), - i: user._id - }); + if (notificationId === undefined || notificationId === null) { + return rej('notification is required'); + } - if (notification === null) { - return rej('notification-not-found'); - } + // Get notifcation + const notification = await Notification + .findOne({ + _id: new mongo.ObjectID(notificationId), + i: user._id + }); - // Update - notification.is_read = true; - Notification.update({ _id: notification._id }, { - $set: { - is_read: true + if (notification === null) { + return rej('notification-not-found'); } - }); - // Response - res(); + // Update + notification.is_read = true; + Notification.update({ _id: notification._id }, { + $set: { + is_read: true + } + }); + + // Response + res(); - // Serialize - const notificationObj = await serialize(notification); + // Serialize + const notificationObj = await serialize(notification); - // Publish read_notification event - event(user._id, 'read_notification', notificationObj); -}); + // Publish read_notification event + event(user._id, 'read_notification', notificationObj); + }); |