fix(api): get completed surveys from db (#52272)
parent
517b4b622e
commit
c762b9075d
|
@ -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({
|
||||
|
|
Loading…
Reference in New Issue