Added a new method for file download and correct csv is getting added.
This commit is contained in:
1 parent
e6b9b5df3c
commit
a1c11fbb3c
2 files changed
+16
-2
No files matched your search
@@ -727,8 +727,7 @@ class MonitorController {
|
|||||||
|
|
||||||
const csv = pkg.unparse(csvData);
|
const csv = pkg.unparse(csvData);
|
||||||
|
|
||||||
return res.success({
|
return res.file({
|
||||||
msg: this.stringService.monitorsExported,
|
|
||||||
data: csv,
|
data: csv,
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/csv",
|
"Content-Type": "text/csv",
|
||||||
|
|||||||
@@ -45,6 +45,21 @@ const responseHandler = (req, res, next) => {
|
|||||||
data,
|
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();
|
next();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user