Skip to content

Commit

Permalink
add createdAt to the excel download
Browse files Browse the repository at this point in the history
  • Loading branch information
JMStudiosJoe committed Apr 26, 2023
1 parent 4e7a8fe commit 0f0e5d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions backend/routes/generateResponsesExcel/generateResponsesExcel.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const QuestionnaireResponse = require('../../models/questionnaireResponse');
const { ObjectId } = require('mongoose').Types;
const xl = require('excel4node');
const fs = require('fs');
const moment = require('moment-timezone');
const langOptions = require('../../LanguageOptions');
router.route('/responses').post((req, res) => {
QuestionnaireResponse.find().then((allResponses) => {
Expand Down Expand Up @@ -53,10 +54,11 @@ router.route('/responses').post((req, res) => {
});

ws.cell(1, 1).string('Workshop Title');
ws.cell(1, 2).string('Red Dot?');
ws.cell(1, 3).string('Agency');
ws.cell(1, 4).string('Email Sent');
ws.cell(1, 5).string('Language');
ws.cell(1, 2).string('Created At');
ws.cell(1, 3).string('Red Dot?');
ws.cell(1, 4).string('Agency');
ws.cell(1, 5).string('Email Sent');
ws.cell(1, 6).string('Language');

Object.keys(questionsColumns).map((question) => {
ws.cell(1, questionsColumns[question])
Expand All @@ -65,14 +67,19 @@ router.route('/responses').post((req, res) => {
});

updatedResponses.map((response, idx) => {
const createdAtFormatted = moment(response.createdAt).format(
'MM/DD/YYYYThh:mm:ss'
);

const langObject = langOptions.LanguageOptions.find(
(item) => item.code === response.language
);
const langDisplay =
(langObject && langObject.englishName) || `Unknown `;
const row = idx + 2;
ws.cell(row, 1).string(response.title).style(style);
ws.cell(row, 2)
ws.cell(row, 2).string(createdAtFormatted).style(style);
ws.cell(row, 3)
.string(response.flag ? 'true' : 'false')
.style(style)
.style({
Expand All @@ -83,13 +90,13 @@ router.route('/responses').post((req, res) => {
fgColor: response.flag ? '#EA2616' : '#ADFF3D',
},
});
ws.cell(row, 3)
ws.cell(row, 4)
.string(response.agency ? response.agency : '')
.style(style);
ws.cell(row, 4)
ws.cell(row, 5)
.string(response.emailSent ? 'true' : 'false')
.style(style);
ws.cell(row, 5).string(langDisplay).style(style);
ws.cell(row, 6).string(langDisplay).style(style);
const qResponses = Object.keys(response.questionnaireResponse);

qResponses.map((qResponse) => {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"express-fileupload": "^1.2.1",
"fuse.js": "^6.4.6",
"jsonwebtoken": "^9.0.0",
"moment-timezone": "^0.5.43",
"mongoose": "^6.10.3",
"node-fetch": "^2.6.1",
"react": "^16.13.1",
Expand Down

0 comments on commit 0f0e5d4

Please sign in to comment.