arielweinberger / nestjs-recipe

NestJS Best Practices Recipe
MIT License
826 stars 437 forks source link

Simpler way to validate enums #1

Closed allanlykkechristensen closed 3 years ago

allanlykkechristensen commented 5 years ago

Rather than creating extra code for checking if status string is a valid TaskStatus enum, you can use Object.values(TaskStatus). It will also make it easier to maintain the code in the future if you add new enums.

nnfans commented 4 years ago

Agree, I already did it too. It always make sense to reference the enum rather than typing it manually. You'll only need to change it once in the task-status.enum.ts

nnfans commented 4 years ago

But for the task status validation pipe you need to declare it manually. There's may be the case that some status cannot be set by the user itself like 'INITIAL' or anything based on your app