feat(utils): Introduce promiseAll util (#5543)

This commit is contained in:
Adrien de Peretti
2023-11-08 08:48:48 +01:00
committed by GitHub
parent e4ce2f4e07
commit f90ba02087
99 changed files with 464 additions and 297 deletions

View File

@@ -3,14 +3,11 @@ import { NextFunction, Request, RequestHandler, Response } from "express"
type handler = (req: Request, res: Response) => Promise<void>
export const wrapHandler = (fn: handler): RequestHandler => {
return (
req: Request & { errors?: Error[] },
res: Response,
next: NextFunction
) => {
if (req?.errors?.length) {
return (req: Request, res: Response, next: NextFunction) => {
const req_ = req as Request & { errors?: Error[] }
if (req_?.errors?.length) {
return res.status(400).json({
errors: req.errors,
errors: req_.errors,
message:
"Provided request body contains errors. Please check the data and retry the request",
})