I'm struggling a bit with the promise template in nodeJS
I search for the user in db and then save a new object with a link to the user, but when the user is not in db, I have to return the rejection, but I'm not sure how to do it correctly.
is there a way how to make it more beautiful?
btw: sorry coffeescript: - [
User.findOne({'fbId':userData.me.id}).exec().then((doc)->
if !doc? then return new Promise (resolve,reject)->reject(404)
video = new Video({
user:doc
state: "queue"
createdAt: new Date()
})
video.save().exec()
)
zajca source
share