Last active
November 25, 2018 17:16
-
-
Save vertonghenb/9a5ea35a22700e3f450f5f36a40b3652 to your computer and use it in GitHub Desktop.
Group 8 - /addRatings/:evaluationid'
This file contains 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
router.post('/addRatings/:evaluationid', function (req, res) { | |
const ids = req.body.map(x => x.competenceID); | |
const incomingRatings = req.body; | |
Rating.findAll({ | |
where: { | |
competenceID: [ids] | |
} | |
}).then(ratings => { | |
incomingRatings.forEach(r => { | |
let foundRating = ratings.find(x => x.competenceID == r.competenceID); | |
if (foundRating) { | |
console.log("found rating...") | |
// update | |
} else { | |
console.log("create rating...") | |
// create | |
} | |
}) | |
}).then(() => { | |
console.log("done updating..."); | |
Evaluation.findByPk(req.params.evaluationid, { | |
include: [{ | |
model: Rating, | |
as: 'ratings', | |
include: [{ | |
model: Teacher, | |
as: 'rater' | |
}] | |
}] | |
}).then(eval => { | |
console.log("Retuning the evaluation"); | |
res.json(eval) | |
}) | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment