fixed overwrite bug when PUTing resources

This commit is contained in:
Ritchie Martori
2012-05-09 19:09:50 -07:00
parent a0670364fb
commit 8d336cbe67
2 changed files with 17 additions and 1 deletions

View File

@@ -50,7 +50,6 @@ module.exports = function (req, res, next, end) {
} else {
module.exec(req, function (err, data) {
res.data = data;
next();
})
}

View File

@@ -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();
})