From 7143429954e091d320d8d57aa0ccc423b2dbfc19 Mon Sep 17 00:00:00 2001 From: avenmia Date: Tue, 15 Aug 2023 15:45:42 -1000 Subject: [PATCH] Add county and region columns to export (#146) * Adding county and location to export. The values are determined by splitting the userSurveyAnswer for the work shop question * Updating location column name to be region --- src/pages/api/export.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/pages/api/export.js b/src/pages/api/export.js index dae3b9a..f30dfcd 100644 --- a/src/pages/api/export.js +++ b/src/pages/api/export.js @@ -75,6 +75,26 @@ const handler = nc({ }, }); + // Gets the row for the survey answer for the question "What is your workshop?" + // This is question 16 in the survey + const surveyAnswerPromise = prisma.userSurveyAnswers.findFirst({ + where: { + userId: row.xid, + questionId: "16", + }, + }); + const surveyPromise = surveyAnswerPromise.then((answer) => { + if (answer !== null) { + let [county, region] = answer.answerValue.split("-"); + row.county = county; + row.region = region; + } else { + row.county = ""; + row.region = ""; + } + return row; + }); + // add census tract and zipcode to the row if they are available const rowPromise = userPromise.then((user) => { var censusTract = ""; @@ -90,9 +110,12 @@ const handler = nc({ // push the row into an array to resolve during end callback output.push(rowPromise); + output.push(surveyPromise); } else { row.censustract = ""; row.zipcode = ""; + row.county = ""; + row.region = ""; output.push(Promise.resolve(row)); } })