Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

478
Views
class-validator - Validate that an array of strings matches a value

I'm using the class-validator npm package and would like to validate that the type property of request body matches one either 'organization' or 'student'.

How would I do this with this package?

This doesn't work:

@IsIn(['organization', 'student'])
type: string

Request body example:

{
   "type": "organization",
   "email": "email@email.com",
   "password": "veryscretpwd"
}
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use something like this in your model class.

{
        "type": {
                type: String,
                enum: ['organization', 'student'],
                required: [true, 'Type is required.']
        },
        "email": ...
}

Instead of @IsIn use enum.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!