After creating a DTO for my endpoint, I encountered an issue where the class-validator stops checking a field if it doesn't have a decorator assigned to it. Even though I need the field to be mandatory and checked, it gets skipped.
DTO:
import {IsNumber} from 'class-validator';
export class Permission {
addNewTask: boolean
updateTask: boolean
addEmployees: boolean
updateEmployees: boolean
addRole: boolean
updateRole: boolean
}
export class AddProjectRolesDto {
@IsNumber()
userId: number
@IsNumber()
projectId: number
permission: Permission
secondErrorExample: any
}
In the code snippet above, I tried processing incoming data but faced an issue where the class-validator fails to parse both the permission object along with its contents and the secondErrorExample that I added for clarity on my problem.
I want to highlight that I utilized @UsePipes(new ValidationPipe())
in my controller.
Example of an incoming object that passed validation due to an error:
{
"userId": 1,
"projectId": 2,
"permission": {}
}
Unfortunately, I haven't been able to find a solution to this particular issue on my own.