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

This commit is contained in:
Tom
2023-11-08 10:37:21 +01:00
committed by GitHub
parent 517b4b622e
commit c762b9075d
+5 -1
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({