Hi,
I have the following
export interface IQuantity {
quantity: string
unit: string
isValid()
}
export class Quantity {
@IsNumberString( { message: gbv_required_msg } )
quantity: string
@IsNotEmpty( { message: gbv_required_msg } )
unit: string
isValid(): boolean {
if ( !_.isNil( this.quantity ) && !_.isNil( this.unit ) ) {
return true
}
return false
}
}
export interface IBleeding {
frequency?: IQuantity
onset?: IOnset
relationToStool?: Array<string>
volume?: IQuantity
}
export class Bleeding{
@ValidateNested()
frequency?: IQuantity = new Quantity()
@ValidateNested()
onset?: IOnset = new Onset()
@ArrayNotEmpty({message: gbv_required_msg})
relationToStool?: Array<string> = []
@ValidateNested()
volume?: IQuantity = new Quantity()
}
Validation is done below:
`
import { observe } from 'universal-observer'
this._observed =
observe( classToPlain( this.bleeding ), change => {
this.dirty = true
this.errors = []
let changeObject = change.object
switch ( this.target ) {
case 'bleedingCmp -> rosCmp': {
transformAndValidate
( Bleeding, changeObject )
.then( ( bleeding: Bleeding ) => {
switch ( change.type ) {
case 'add':
this.bleedingData.emit( updatePayload1( bleeding, change.type, this.payload ) )
this._store$.dispatch(
{
type: BleedingAction.ADD_ROS_DATA,
payload: changeObject
} )
break
case 'update':
this.bleedingData.emit( updatePayload1( bleeding, change.type, this.payload ) )
this._store$.dispatch(
{
type: BleedingAction.UPDATE_ROS_DATA,
payload: changeObject
} )
break
}
} )
.catch( errors => {
this.errors = errors
console.log(errors)
}
break
}
} )
`
The errors printed to the console NEVER include errors of the propertes, nested (decorated with @ValidateNested() properties.
What am I doing wrong?
Cheers
Duplicate of https://github.com/pleerock/class-validator/issues/83 @ValidateNested is not working properly, it's not an issue with your code.
@st-clair-clarke @NoNameProvided In that post I explain how I got it working
Closing in favor of #83
Most helpful comment
@st-clair-clarke @NoNameProvided In that post I explain how I got it working