Open Char2sGu opened 3 years ago
https://thenightmarex.github.io/blogs/2021/07/17/using-the-pipe-to-validate-everything-in-nestjs/
nest 与 class-validator 可以完美整合,对于数据结构、类型的验证,nest 和 class-validator 都有详细的文档,在此不再赘述。然而需要验证的不止有数据结构和字段类型,还有各式的业务需求,这是没有文档提及的。大多数的 nest 使用者选择直接在 services 中进行数据验证,但这样就导致了不优雅的高耦合的代码, nest 推荐使用 pipes 集中验证数据 ,
https://thenightmarex.github.io/blogs/2021/07/17/using-the-pipe-to-validate-everything-in-nestjs/
nest 与 class-validator 可以完美整合,对于数据结构、类型的验证,nest 和 class-validator 都有详细的文档,在此不再赘述。然而需要验证的不止有数据结构和字段类型,还有各式的业务需求,这是没有文档提及的。大多数的 nest 使用者选择直接在 services 中进行数据验证,但这样就导致了不优雅的高耦合的代码, nest 推荐使用 pipes 集中验证数据 ,