Closed anaismveras closed 2 years ago
I think you can put a conditional in there that will execute one promise or the other. So if the input name = "comment" .then() destroy comment -- else if the input name = "pet" .then() destrory pet
destroy comment and then .then() ---- sorry obviously the syntax there is wrong, but does the concept make sense?
i got it to work another way, I realized I needed a nested .then and I also needed to change the link
router.post('/:animal_id/comments', isLoggedIn, (req, res) => {
// console.log('this is req.body', req.body)
db.note.create({
animalId: req.params.animal_id,
userId: res.locals.currentUser.id,
description:req.body.description
})
.then(resPost => {
// console.log('this is resPost', resPost)
res.redirect(`/profile/${req.params.animal_id}`)
})
.catch(error => {
// console.log(error)
res.send('invalid comment', error)
})
})
nice!
I have two router.deletes in the profile.js because one button is to delete the actual favorited pet and one is to delete the comment but they both kinda over lap each other in some way even though the URL for both of them arent the same.