Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SIRE
backend
Commits
dd9c0cfc
Commit
dd9c0cfc
authored
1 year ago
by
Douglas Sobreira Garcia
Browse files
Options
Download
Email Patches
Plain Diff
FINAL FIX
parent
98d27576
Pipeline
#12869
failed with stage
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/controllers/reportController.js
+33
-0
src/controllers/reportController.js
src/routes/reportRoutes.js
+1
-0
src/routes/reportRoutes.js
with
34 additions
and
0 deletions
+34
-0
src/controllers/reportController.js
View file @
dd9c0cfc
...
...
@@ -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
This diff is collapsed.
Click to expand it.
src/routes/reportRoutes.js
View file @
dd9c0cfc
...
...
@@ -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
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help