Created
August 8, 2018 13:17
-
-
Save namila007/7204be5042c5db69bef53e4474e3407e to your computer and use it in GitHub Desktop.
Returning Mongoose promise from a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function (status) { | |
return isFav.isFavourited(userid, status) | |
.then((res) => { | |
return res | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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