Clean up
This commit is contained in:
		| @@ -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'); | ||||
| 	} | ||||
| 		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 | ||||
| 		// Get notifcation | ||||
| 		const notification = await Notification | ||||
| 			.findOne({ | ||||
| 				_id: new mongo.ObjectID(notificationId), | ||||
| 				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) { | ||||
| 		return rej('notification-not-found'); | ||||
| 	} | ||||
| 		// Response | ||||
| 		res(); | ||||
|  | ||||
| 	// Update | ||||
| 	notification.is_read = true; | ||||
| 	Notification.update({ _id: notification._id }, { | ||||
| 		$set: { | ||||
| 			is_read: true | ||||
| 		} | ||||
| 		// Serialize | ||||
| 		const notificationObj = await serialize(notification); | ||||
|  | ||||
| 		// Publish read_notification event | ||||
| 		event(user._id, 'read_notification', notificationObj); | ||||
| 	}); | ||||
|  | ||||
| 	// Response | ||||
| 	res(); | ||||
|  | ||||
| 	// Serialize | ||||
| 	const notificationObj = await serialize(notification); | ||||
|  | ||||
| 	// Publish read_notification event | ||||
| 	event(user._id, 'read_notification', notificationObj); | ||||
| }); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Aya Morisawa
					Aya Morisawa