Skip to content

Instantly share code, notes, and snippets.

@vertonghenb
Last active November 25, 2018 17:16
Show Gist options
  • Save vertonghenb/9a5ea35a22700e3f450f5f36a40b3652 to your computer and use it in GitHub Desktop.
Save vertonghenb/9a5ea35a22700e3f450f5f36a40b3652 to your computer and use it in GitHub Desktop.
Group 8 - /addRatings/:evaluationid'
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