mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-01-08 02:39:44 -06:00
Added a new method for file download and correct csv is getting added.
This commit is contained in:
@@ -727,8 +727,7 @@ class MonitorController {
|
||||
|
||||
const csv = pkg.unparse(csvData);
|
||||
|
||||
return res.success({
|
||||
msg: this.stringService.monitorsExported,
|
||||
return res.file({
|
||||
data: csv,
|
||||
headers: {
|
||||
"Content-Type": "text/csv",
|
||||
|
||||
@@ -45,6 +45,21 @@ const responseHandler = (req, res, next) => {
|
||||
data,
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Sends a raw file response (for CSV, PDF, etc.)
|
||||
* @param {Object} options
|
||||
* @param {Buffer|string} options.data - The file content
|
||||
* @param {Object} options.headers - Headers to set (e.g. Content-Type, Content-Disposition)
|
||||
* @param {number} [options.status=200] - HTTP status code
|
||||
*/
|
||||
res.file = ({ data, headers = {}, status = 200 }) => {
|
||||
Object.entries(headers).forEach(([key, value]) => {
|
||||
res.setHeader(key, value);
|
||||
});
|
||||
return res.status(status).send(data);
|
||||
};
|
||||
|
||||
next();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user