I am currently working on implementing a logic to validate whether all HTTP body properties are mandatory in my DTO. I have managed to access the request body using a custom decorator and an interceptor in Nestjs, but during validation, I face the challenge of verifying if the body properties are part of my DTO props - which I can't access directly.
Although this is a TypeScript related inquiry, I wanted to provide context so that anyone who might know an alternative approach to achieve what I am attempting can share their insights.
Here is a snippet showcasing the DTO with properties I am trying to access:
export class CreateUserDTO {
@IsString()
@IsNotEmpty()
name: string;
@IsEmail()
email: string;
@MinLength(6)
@MaxLength(32)
@IsAlphanumeric()
password: string;
@IsOptional()
@IsDateString()
birthAt: string | Date;
}
// attempts made to access properties in transpilation time, without success as they remain undefined
console.log(CreateUserDTO.prototype.birthAt);
console.log(CreateUserDTO.birthAt);