DEV Community

Kazi Abdur Rakib
Kazi Abdur Rakib

Posted on

sendResponse dynamic function create

//==>src/app/utils/sendResponse.ts

import { Response } from 'express';

type TResponse<T> = {
  statusCode: number;
  success: boolean;
  message?: string;
  data: T;
};

const sendResponse = <T>(res: Response, data: TResponse<T>) => {
  res.status(data?.statusCode).json({
    success: data.success,
    message: data.message,
    data: data.data,
  });
};

export default sendResponse;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)