diff --git a/lib/resource.js b/lib/resource.js index cf7699c..f2891f7 100644 --- a/lib/resource.js +++ b/lib/resource.js @@ -50,7 +50,6 @@ module.exports = function (req, res, next, end) { } else { module.exec(req, function (err, data) { res.data = data; - next(); }) } diff --git a/lib/storage.js b/lib/storage.js index f206b35..2f6d255 100644 --- a/lib/storage.js +++ b/lib/storage.js @@ -27,6 +27,23 @@ module.exports = require('mdoq') // build full mongodb url this.url = url + (path || this.url); + if(req.method === 'PUT' && req.resource && req.resource.type != 'Static') { + var oldBody = req.body + , body = {$set: oldBody.$set || {}}; + + Object.keys(oldBody).forEach(function (p) { + if(p === '$set') return; + if(p && p[0] === '$') { + body[p] = oldBody[p]; + } else { + body.$set[p] = oldBody[p]; + } + }) + + // rewrite body to $set + req.body = body; + } + end(mongo); next(); })