ajout endpoint POST pour ajout avis

This commit is contained in:
2022-12-24 16:11:40 +01:00
parent 70396e0dc1
commit beb7e26ce7
6 changed files with 38 additions and 11 deletions

View File

@@ -37,9 +37,19 @@ const addReview = (review, authorId, sourceId) => {
}
export const addReviewFromRequest = async (req,res) => {
const author = new Auteur(req.body.auteur_age,req.body.auteur_sexe);
const review = new Review(author, req.body.note, req.body.source, req.body.message, req.body.notes_autre)
let authorId = await addAuteur(author);
let sourceId = await getSourceId(review.source);
await addReview(review, authorId, sourceId )
try {
let notes_autre = {}
try{
notes_autre = JSON.parse(req.body.notes_autre);
}catch(err){};
const author = new Auteur(req.body.auteur_age,req.body.auteur_sexe);
const review = new Review(author, req.body.note, req.body.source, req.body.commentaire, notes_autre)
let authorId = await addAuteur(author);
let sourceId = await getSourceId(review.source);
await addReview(review, authorId, sourceId );
res.send("success")
}catch(err) {
res.status(500).send("Error : " + err.message)
}
}