Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add county and region columns to export #146

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/pages/api/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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));
}
})
Expand Down
Loading