本文整理汇总了TypeScript中express-validator/check.validationResult函数的典型用法代码示例。如果您正苦于以下问题:TypeScript validationResult函数的具体用法?TypeScript validationResult怎么用?TypeScript validationResult使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了validationResult函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: validationResult
export const errorHandler = (req: any, res: any, next: any) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
res.status(ERROR_CODES.ERROR_CODE_GENERIC).json({message: errors.array()[0].msg});
} else {
next();
}
};
示例2: handleValidationResult
export function handleValidationResult(req: Request, res: Response, next: NextFunction): void {
const errors = validationResult(req);
if (false === errors.isEmpty()) {
res.status(422).json({ errors: errors.array() });
} else {
next();
}
};
示例3: areValidationErrors
function areValidationErrors (req: express.Request, res: express.Response) {
const errors = validationResult(req)
if (!errors.isEmpty()) {
logger.warn('Incorrect request parameters', { path: req.originalUrl, err: errors.mapped() })
res.status(400).json({ errors: errors.mapped() })
return true
}
return false
}
示例4: async
router.post('/:id', CREATE_ORDER_VALIDATIONS, async (req: Request, res: Response) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(422).json({ errors: errors.mapped() });
}
// matchedData returns only the subset of data validated by the middleware
const orderData = matchedData(req);
let detailsObj = orderData.details || {};
let details: Array<
Pick<OrderDetail, 'id' | 'productid' | 'quantity' | 'unitprice' | 'discount'>
> = normalizeOrderDetails(detailsObj);
try {
let order = await updateOrder(req.params.id, orderData as any, details); // * update the data
res.redirect(`/orders/${order.id}`);
} catch (e) {
res.status(500);
res.send(e.toString());
}
});