UNPKG

responsify-requests

Version:

This package will help you throw the response messages along with the proper status code and proper structure.

46 lines (42 loc) 1.37 kB
const responseType = require('./constants/responseType'); const statusCode = require('./constants/statusCode') const response = (res, data, status, message, response) => { if (status === 1 && response === responseType.SUCCESS) { res.status(statusCode.SUCCESS).json({ message: message, data: data, status: status, }); } else if (status === 0 && response === responseType.UNAUTHORIZED) { res.status(statusCode.UNAUTHORIZED).json({ message: message, status: status, }); } else if (status === 0 && response === responseType.NOT_FOUND) { res.status(statusCode.NOT_FOUND).json({ message: message, status: status, }); } else if (status === 0 && response === responseType.BAD_REQUEST) { res.status(statusCode.BAD_REQUEST).json({ message: message, status: status, }); } else if (status === 0 && response === responseType.TOO_MANY_REQUESTS) { res.status(statusCode.TOO_MANY_REQUESTS).json({ message: message, status: status, }); } else if (status === 0 && response === responseType.UNPROCESSABLE_ENTITY) { res.status(statusCode.UNPROCESSABLE_ENTITY).json({ message: message, status: status, }) } else { res.status(statusCode.SERVER_ERROR).json({ message: message, status: status, }); } }; module.exports = response;