#Validation doesn't work for nested objects

1 messages · Page 1 of 1 (latest)

wind plover
#

I use validateOrReject function from "class-validator" for validating object in my service, but I noticed that validation doesn't work when object are nested.

object which I pass to validateOrReject () function is instance of classDTO(using class-validator )

hard mantle
#

What does the class representation of the object you are validating look like?

wind plover
# hard mantle What does the class representation of the object you are validating look like?

class PointDto{
@jagged micaNotEmpty()
@jagged micaString()
name: string;

@jagged micaNotEmpty()
@jagged micaInt()
amount: number;
}

class TestDto {
@jagged micaNotEmpty()
@jagged micaString()
name: string;

@jagged micaNotEmpty()
@violet micaidateNested()
@buoyant nebulape(() => PointDto)
point: PointDto;
}

/////////////////////////////
Here is my logic in service :

const test = new TestDto();

test.name = "Name";
test.point = {
name: "point",
amount: 10
};

await validateOrReject(test);

hard mantle
#

Shouldn't test.point be an instance of the Point class?