redThread / server /src /utils /response.js
3v324v23's picture
Initial commit of RedThread project
0dd2082
raw
history blame contribute delete
660 Bytes
function success(res, data, statusCode = 200) {
return res.status(statusCode).json({
success: true,
timestamp: new Date().toISOString(),
...data,
});
}
function paginate(items, page = 1, limit = 10) {
const start = (page - 1) * limit;
const end = start + limit;
const results = items.slice(start, end);
return {
results,
pagination: {
page,
limit,
total: items.length,
totalPages: Math.ceil(items.length / limit),
hasNext: end < items.length,
hasPrev: page > 1,
},
};
}
module.exports = { success, paginate };