UNPKG

data-transfer-object

Version:

Data Transfer Object class built on `class-validator`.

11 lines (10 loc) 500 B
/** * Receives an array of `ValidationError`, and generates an object with key-value pairs where * the keys represent a property name, and the values are an array of all validation error * messages for that property. * @param errors The array of `ValidationError` to generate a validation error map from. */ export function getValidationErrorMap(errors) { const entries = errors.map(e => [e.property, Object.values(e.constraints ?? {})]); return Object.fromEntries(entries); }