我期望来自前端的数据数组类似于以下示例:
{
"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) => {
})
我无法找到一种方法来做到这一点。预先感谢。