打字稿-Express-Validator验证数组的类型

时间:2020-10-09 13:04:04

标签: javascript node.js typescript express typescript-typings

我期望来自前端的数据数组类似于以下示例:

{
   "interests": [ "music", "art" ] // etc 
}

我为此创建了一个枚举:

export enum categories {
  DESIGN = 'design',
  ART = 'art',
  WRITING = 'writing',
  FASHION = 'fashion',
  PHOTOGRAPHY = 'photography',
  ARCHITECTURE = 'architecture',
  MUSIC = 'music',
  GAMING = 'gaming',
  DIGITAL = 'digital',
  MEDIA = 'media'
}

这是猫鼬如何验证文档属性=> interests: categories[]

目标是

要验证客户端发送的数组的类型为categories[]

router.post('/api/project/interest/add', [
  body('interests').isArray()
], authenticate, async (req: Request, res: Response) => {
})

我无法找到一种方法来做到这一点。预先感谢。

0 个答案:

没有答案