Skip to content

Instantly share code, notes, and snippets.

@namila007
Created August 8, 2018 13:17
Show Gist options
  • Save namila007/7204be5042c5db69bef53e4474e3407e to your computer and use it in GitHub Desktop.
Save namila007/7204be5042c5db69bef53e4474e3407e to your computer and use it in GitHub Desktop.
Returning Mongoose promise from a function
async function (status) {
return isFav.isFavourited(userid, status)
.then((res) => {
return res
})
}
const promisify = require('bluebird')
require('mongoose').Promise = promisify
const Favourite = require('../models/favourite.model')
module.exports = {
async isFavourited (userid, status) {
return Favourite
.findOne({
user_id: userid, status_id: status._id
})
.lean()
.exec()
.catch((err) => { return err })
.then((res) => {
if (res) status.is_favourited = true
else status.is_favourited = false
return Promise.resolve(status)
})
.catch((err) => { return err })
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment