UNPKG

u-mongoose-expressapi

Version:

Common functions for Express and Mongoose API

21 lines (17 loc) 595 B
exports.Response = (res, code, message, data, total, custom) => { // Construct the Record object let Record = {}; let status = code < 300 ? 'SUCCESS' : 'ERROR'; // Add tableData to the Record object if it's provided if (data !== undefined) { Record.data = data; // Record.tableData = data; } // Add total to the Record object if it's provided if (total !== undefined) { Record.total = total; } // Return the response return res.status(code).json({ ...Record, ...custom, status, message }); // return res.status(code).json({ Record,status,message}); };