I have this type:
export type BranchOperatorRole = 'none' | 'seller' | 'operator' | 'administrator';
With which class-validator decorator can I validate that a property has one of those values?
import { IsEmail, IsString, Contains } from "class-validator";
export type BranchOperatorRole = 'none' | 'seller' | 'operator' | 'administrator';
export class AddBranchOperatorRequest extends User {
@IsEmail()
email: string;
@Contains(BranchOperatorRole )
role: BranchOperatorRole;
}
const roles = ['none', 'seller', 'operator', 'administrator'] as const;
export type BranchOperatorRole = typeof roles[number];
export class AddBranchOperatorRequest extends User {
@IsEmail()
email: string;
@IsIn(roles)
role: BranchOperatorRole;
}
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