Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 doPut(instance, next) {
//update & persist instance
if (body && !_.isEmpty(body)) {
// copy existing paths & merge with updates
const exists = _.pick(copyInstance(instance), ..._.keys(body));
const changes = mergeObjects(exists, body);
instance.set(changes);
}
instance.updatedAt = new Date();
instance.save(function afterSave(error, saved) {
next(error, saved);
});
},
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 doPatch(instance, next) {
//update & persist instance
if (body && !_.isEmpty(body)) {
// copy existing paths & merge with updates
const exists = _.pick(copyInstance(instance), ..._.keys(body));
const changes = mergeObjects(exists, body);
instance.set(changes);
}
instance.updatedAt = new Date();
instance.save(function afterSave(error, saved) {
next(error, saved);
});
},
FileSchema.methods.write = function write(stream, done) {
// obtain file writable details
const file = _.pick(copyInstance(this), WRITABLES);
// stream file to gridfs
bucket.writeFile(file, stream, function afterWriteFile(error, created) {
// back-off error
if (error) {
done(error);
}
//read file details
else {
this.constructor.findById(created._id, done);
}
}.bind(this));
};
schema.statics.post = function post(body, done) {
//instantiate model
const instance = (
isInstance(body) ?
body :
new this(copyInstance(body))
);
//persist model
instance.post(done);
};