mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(api): get completed surveys from db (#52272)
This commit is contained in:
@@ -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({
|
||||
|
||||
Reference in New Issue
Block a user