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)); } })