Before we can consider persisting data off to storage, we need to ensure the data is in a known good shape. This means validation. And there is a really nice library that solves this problem very effectively for us.
We will be using the Class Validator library.
This will solve all our validation concerns, and even take care of creating a lovely error object that we can return to our API consumers.
We didn't add this library at the start of our project as there is a touch extra setup required. Let's take care of this now.
Смотрите видео Create a NodeJS API with Koa and TypeScript - #8 - Easy Validation with Class Validator онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь Code Review Videos 04 Май 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 3,355 раз и оно понравилось 40 людям.