How to check whether the array is empty or not using class-validator.
Given below is my structure. I want to check if cartId is empty or not.
{
"cartId": []
}
What you want is @ArrayNotEmpty().
You can find all built-in validators here: https://github.com/typestack/class-validator#validation-decorators
If you don't find - you can write your own validator: https://github.com/typestack/class-validator#custom-validation-classes
To check if array is empty, you can use @ArrayNotEmpty(), like this:
@ArrayNotEmpty({ each: true })
cartId: [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With