From 0f0e5d466b734a71e6c9607e2ba60fbbd1fc85f9 Mon Sep 17 00:00:00 2001 From: Joseph Richardson Date: Wed, 26 Apr 2023 07:59:01 -0700 Subject: [PATCH] add createdAt to the excel download --- .../generateResponsesExcel.js | 23 ++++++++++++------- package.json | 1 + 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/backend/routes/generateResponsesExcel/generateResponsesExcel.js b/backend/routes/generateResponsesExcel/generateResponsesExcel.js index 3d7decee..444e6e07 100644 --- a/backend/routes/generateResponsesExcel/generateResponsesExcel.js +++ b/backend/routes/generateResponsesExcel/generateResponsesExcel.js @@ -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) => { @@ -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]) @@ -65,6 +67,10 @@ 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 ); @@ -72,7 +78,8 @@ router.route('/responses').post((req, res) => { (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({ @@ -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) => { diff --git a/package.json b/package.json index 2c3364f4..35b5c18b 100644 --- a/package.json +++ b/package.json @@ -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",