fix(api): get completed surveys from db (#52272)

pull/52281/head
Tom 2023-11-08 03:37:21 -06:00 committed by GitHub
parent 517b4b622e
commit c762b9075d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -225,9 +225,13 @@ function createPostSubmitSurvey(app) {
return async function postSubmitSurvey(req, res) {
const { user, body } = req;
const { surveyResults } = body;
const { completedSurveys = [] } = user;
const { id: userId } = user;
const { title } = surveyResults;
const completedSurveys = await Survey.find({
where: { userId }
});
const surveyAlreadyTaken = completedSurveys.some(s => s.title === title);
if (surveyAlreadyTaken) {
return res.status(400).json({