In mongoose.js after every query the functions returns (error, result). I would like to write function of my own that does the same.
I thought the answer was to use promises so I wrote this
login: (user) ->
q.Promise (resolve, reject, notify) ->
console.log resolve
if _.has(user, 'password')
dashboard.users.find(user).exec().then (err, results) ->
if err then reject("Error occurred with the database")
if results then resolve(results) else reject("User not found")
else
reject("A password is required for login")
Auth.login(testuser).then (d) ->
console.log d, "done"
but after research I found that this is an anti pattern and the code does not work (promise is never resolved/rejected). So now I am not sure what to do.