import { Request, Response, NextFunction } from 'express';

// Type for the asyncHandler callback function
type AsyncHandlerCallback = (req: Request, res: Response, next: NextFunction) => Promise<void> | void;

// The asyncHandler function
const asyncHandler = (cb: AsyncHandlerCallback) => 
  (req: Request, res: Response, next: NextFunction): void => {
    Promise.resolve(cb(req, res, next))
      .catch(next);
};

export default asyncHandler;