import { ValidationError } from 'class-validator' ; export class FormData { constructor ( public readonly values = { } , public readonly errors = [ ] ) { } private getPropertyError ( property ) { return this . errors . find ( error => error . property === property ) ; } hasErrors ( ) { return this . errors . length !== 0 ; } hasPropertyError ( property ) { return ! ! this . getPropertyError ( property ) ; } getPropertyValue ( property ) { return this . values [ property ] || '' ; } getPropertyErrorMessages ( property ) { const errors = this . getPropertyError ( property ) ; if ( ! errors ) { return [ ] ; } const { constraints } = errors ; return Object . entries ( constraints ) . map ( ( [ , errorMsg ] ) => errorMsg ) ; } }