Commit dd9c0cfc authored by Douglas Sobreira Garcia's avatar Douglas Sobreira Garcia
Browse files

FINAL FIX

parent 98d27576
Pipeline #12869 failed with stage
Showing with 34 additions and 0 deletions
+34 -0
......@@ -68,4 +68,37 @@ exports.getReportByUserId = async (req, res, next) => {
} catch (error) {
next(error);
}
};
exports.getReportByRoomId = async (req, res, next) => {
try {
await classifyAndGenerateCSVReport();
const request = req.params.roomId;
const data = await Message.find({ 'room': request });
if (data) {
const reportDto = new ReportDto(data);
const fields = Object.keys(reportDto);
const csv = new Parser({ fields }).parse(reportDto);
const fileName = 'report.csv';
fs.writeFileSync(fileName, csv);
res.setHeader('Content-Type', 'text/csv');
res.download(fileName, fileName, (err) => {
if (err) {
res.status(500).send('Erro ao baixar o arquivo.');
}
fs.unlinkSync(fileName);
});
} else {
return res.status(404).json({ message: `Report not found by Id: ${request}` });
}
} catch (error) {
next(error);
}
};
\ No newline at end of file
......@@ -5,5 +5,6 @@ const reportController = require('../controllers/reportController');
router.get('/', reportController.getAllReports);
router.get('/:senderId', reportController.getReportByUserId);
router.get('/room/:roomId', reportController.getReportByRoomId);
module.exports = router;
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment