API: very rudimentary implementation of _v. We'll have a proper

implementation in APIv2, but this will help with performance for rewrite
& mobile
This commit is contained in:
Tyler Renelle
2013-08-28 17:21:36 -04:00
parent 13a4aadfb4
commit 72a26d35bb
3 changed files with 16 additions and 7 deletions
+4 -1
View File
@@ -34,6 +34,7 @@ api.auth = (req, res, next) ->
User.findOne {_id: uid, apiToken: token}, (err, user) ->
return res.json(500, {err}) if err
return res.json(401, NO_USER_FOUND) if _.isEmpty(user)
res.locals.wasModified = +user._v isnt +req.query._v
res.locals.user = user
next()
@@ -423,6 +424,8 @@ api.batchUpdate = (req, res, next) ->
async.series actions, (err) ->
res.json = oldJson; res.send = oldSend
return res.json(500, {err}) if err
res.json 200, user
response = user.toJSON()
response.wasModified = res.locals.wasModified
res.json 200, response
console.log "Reply sent"