UNPKG

easy-express-cwa

Version:

CLI tool to setup a common Express.js backend developed by codewithashim

28 lines (23 loc) 592 B
import { Response } from 'express'; type IApiReponse<T> = { statusCode: number; success: boolean; message?: string | null; meta?: { page: number; limit: number; total: number; }; data?: T | null; }; const sendReponse = <T>(res: Response, data: IApiReponse<T>): void => { const responseData: IApiReponse<T> = { statusCode: data.statusCode, success: data.success, message: data.message || null, meta: data.meta || null || undefined, data: data.data || null, }; res.status(data.statusCode).json(responseData); }; export default sendReponse;