I'm bit fighting with promise pattern in nodeJS
I'm looking for user in db and then saving new entity with user reference, but when user is not in db, I should return rejection, but I'm not sure how to do it properly.
is there way how to do it more nicely?
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()
)