Created
March 28, 2017 09:39
-
-
Save zapkub/ea1bad0c3c8682043447e69b0c37dd5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// args | |
// questionId, selectedChoiceId | |
const question = await Question.findById(id); | |
// search if questionId is exist | |
if(question.answers.filter( answer => answer.questionId === questionId ).length === 0){ | |
question.answers.push({ questionId, selectedChoiceId }); | |
} else { | |
// find and update | |
question.answers = question.answer.map((answer, index) => { | |
if(answer.questionId === questionId) { | |
answer.selectedChoiceId = selectedChoiceId; | |
} | |
}); | |
} | |
await question.save(); | |
// return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment