Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- newExam = async (req, res)=>{
- hasItUsernameTwo(req,res)
- const user = await User.findById(req.user),
- examData = JSON.parse(req.body.deepFormJSON),
- newExam = new Exam();
- console.log(examData)
- console.log(examData)
- newExam.title = examData.title
- newExam.description = examData.description
- newExam.author = user.username
- newExam.questions = []
- // para crear el array de objetos con preguntas
- if(Array.isArray(examData.questions.question)){
- examData.questions.question.forEach(e => {
- newExam.questions.push({
- question: e,
- })
- })
- for (var i = 0; i < examData.questions.question; i++) {
- newExam.questions[i].answers = []
- }
- } {
- newExam.questions.push({
- question: examData.questions.question
- })
- newExam.questions.answers = []
- }
- // para crear el array con las respuestas de cada pregunta
- // const get = examData.questions.answers.answer.forEach(async (e, i, array) => {
- // if(Array.isArray(examData.questions.question)){
- // newExam.questions[i].answers.push({answer: e})
- // } {
- // newExam.questions.answers.push({answer: e})
- // }
- // // return newExam.save()
- // });
- // await Promise.all(get)
- for (const [i, e] of examData.questions.answers.answer.entries()){
- if(Array.isArray(examData.questions.question)){
- newExam.questions[i].answers.push({answer: e})
- newExam.questions[i].markModified("answers")
- } {
- newExam.questions.answers.push({answer: e})
- newExam.markModified("answers")
- }
- }
- // for (const [i, e] of examData.questions.answers.correct.entries()){
- // if(Array.isArray(examData.questions.question)){
- // for(const [index, element] of newExam.questions[i].answers.entries()){
- // }
- // } {
- // for(const [index, element] of newExam.questions.answers.entries()){
- // }
- // }
- // }
- console.log(newExam.questions.answers)
- // para crear el array con los valores buleanos de cada pregunta
- // await newExam.save();
- // await newExam.validate();
- // user.exams.push(newExam._id)
- // await user.save()
- console.log(newExam)
- // res.redirect(`exams/${newExam._id}`)
- res.redirect(`/`)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement