UNPKG

@decaf-ts/decorator-validation

Version:
53 lines 1.66 kB
/** * @summary Helper Class to hold the error results * @description holds error results in an 'indexable' manner * while still providing the same result on toString * * @param {ModelErrors} errors * * @class ModelErrorDefinition * * @category Model */ export class ModelErrorDefinition { constructor(errors) { for (const prop in errors) { if (Object.prototype.hasOwnProperty.call(errors, prop) && errors[prop]) Object.defineProperty(this, prop, { enumerable: true, configurable: false, value: errors[prop], writable: false, }); } } /** * @summary Outputs the class to a nice readable string * * @override */ toString() { const self = this; return Object.keys(self) .filter((k) => Object.prototype.hasOwnProperty.call(self, k) && typeof self[k] !== "function") .reduce((accum, prop) => { let propError = Object.keys(self[prop]).reduce((propAccum, key) => { if (!propAccum) propAccum = self[prop][key]; else propAccum += `\n${self[prop][key]}`; return propAccum; }, undefined); if (propError) { propError = `${prop} - ${propError}`; if (!accum) accum = propError; else accum += `\n${propError}`; } return accum; }, ""); } } //# sourceMappingURL=ModelErrorDefinition.js.map