@mountyco/mongoose-wayback
Version:
Wayback plugin for mongoose models.
37 lines • 1.1 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var deep_diff_1 = require("deep-diff");
var resolveUser = function (newObject) {
var user = (newObject).__user;
if (!user) {
throw new Error("unable to get user information");
}
delete newObject.__user;
return user;
};
exports.resolveUser = resolveUser;
var hasChanges = function (newObject, oldObject) {
var _c;
var _a = newObject.toJSON();
var _b = oldObject.toJSON();
var changes = (deep_diff_1.diff(_a, _b));
changes = (_c = changes) === null || _c === void 0 ? void 0 : _c.filter(function (x) {
if (x.path && typeof x.path == 'string') {
if (x.path == 'updatedAt') {
return false;
}
}
if (x.path && Array.isArray(x.path)) {
if (x.path.indexOf('updatedAt') >= 0) {
return false;
}
}
return true;
});
if (changes && changes.length) {
return true;
}
return false;
};
exports.hasChanges = hasChanges;
//# sourceMappingURL=utils.js.map