Files
vitfit-r2/V2/app/core/respond.js
T
2026-06-13 08:03:45 -04:00

34 lines
604 B
JavaScript

'use strict';
function ok(res, data) {
res.status(200).json({ data });
}
function created(res, data) {
res.status(201).json({ data });
}
function collection(res, data, total, page, limit) {
res.status(200).json({
data,
meta: {
total,
page,
limit,
totalPages: Math.ceil(total / limit),
},
});
}
function noContent(res) {
res.status(204).end();
}
function err(res, code, message, status, field) {
res.status(status).json({
error: { code, message, ...(field ? { field } : {}) },
});
}
module.exports = { ok, created, collection, noContent, err };