Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (field.trim) {
if (field.trim === true)
value = value.trim();
else if (field.trim === "right")
value = value.trimRight();
else if (field.trim === "left")
value = value.trimLeft();
}
// TODO: more sanitization
// - lowercase, uppercase, ...etc
// Validating
if (value == undefined) {
if (field.required && isNew)
promises.push(Promise.reject(new ValidationError(`The '${field.name}' field is missing.`))); // TODO
return;
}
/**
* TODO:
* - custom validate fn
* - min, max for number
* - pattern for string
*/
_.set(entity, field.name, value);
// Because the key is the path. Mongo overwrites a nested object if set a nested object
updates[field.name] = value;
};
async handler(ctx) {
if (ctx.params.key == null)
throw new ValidationError("Param 'key' must be defined.", "ERR_KEY_NOT_DEFINED");
return await this.transformDocuments(ctx, {}, await this.get(ctx.params.key));
}
},
this.settings.entityValidator = entity => {
const res = check(entity);
if (res === true)
return this.Promise.resolve();
else
return this.Promise.reject(new ValidationError("Entity validation error!", null, res));
};
}
this.settings.entityValidator = entity => {
const res = check(entity);
if (res === true)
return Promise.resolve();
else
return Promise.reject(new ValidationError("Entity validation error!", null, res));
};
}