|
|
|
@ -125,8 +125,20 @@ function deepCopy (obj) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set field to value in a model |
|
|
|
|
* Create it if it doesn't exist |
|
|
|
|
* @param {Object} obj The model to set a field for |
|
|
|
|
* @param {Object} mod mod is of the form { k: v }. k is the field, v its value |
|
|
|
|
* k can contain dots, in that case that means we will set a subfield |
|
|
|
|
*/ |
|
|
|
|
modifierFunctions.$set = function (obj, mod) { |
|
|
|
|
var field, value; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
modifierFunctions.$inc = function () {}; |
|
|
|
|
modifierFunctions.$set = function () {}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -154,7 +166,19 @@ function modify (obj, updateQuery) { |
|
|
|
|
// Apply modifiers
|
|
|
|
|
modifiers = _.uniq(keys); |
|
|
|
|
modifiers.forEach(function (m) { |
|
|
|
|
var keys; |
|
|
|
|
|
|
|
|
|
if (!modifierFunctions[m]) { throw "Unknown modifier " + m; } |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
keys = Object.keys(updateQuery[m]); |
|
|
|
|
} catch (e) { |
|
|
|
|
throw "Modifier " + m + "'s argument must be an object"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
keys.forEach(function (k) { |
|
|
|
|
modifierFunctions[m](obj, k, updateQuery[m][k]); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|