Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function findExisting(next) {
if (isInstance(model)) {
next(null, model);
} else {
// prepare find query
const findQuery = Model.findById(model._id);
// if filter
if (model.filter) {
findQuery.where(model.filter);
}
findQuery.orFail().exec(next); //TODO use getById
}
},
const updatesFor = (id, updates) => {
// normalize id
const options = _.isPlainObject(id) ? id : { _id: id };
// ignore self instance updates
if (isInstance(updates) && updates._id === options._id) {
return updates;
}
// compute updates
const changes = mergeObjects(copyInstance(updates), options);
return changes;
};
const updatesFor = (id, updates) => {
// normalize id
const options = _.isPlainObject(id) ? id : { _id: id };
// ignore self instance updates
if (isInstance(updates) && updates._id === options._id) {
return updates;
}
// compute updates
const changes = mergeObjects(copyInstance(updates), options);
return changes;
};
function afterFindExisting(instance, next) {
// handle instance
if (isInstance(model)) {
model.patch({ updatedAt: new Date() }, next);
}
// handle updates
else {
delete model._id;
delete model.id;
instance.patch(model, next);
}
}
function afterFindExisting(instance, next) {
// handle instance
if (isInstance(model)) {
model.put({ updatedAt: new Date() }, next);
}
// handle updates
else {
delete model._id;
delete model.id;
instance.put(model, next);
}
}
schema.statics.post = function post(body, done) {
//instantiate model
const instance = (
isInstance(body) ?
body :
new this(copyInstance(body))
);
//persist model
instance.post(done);
};