From 4815e3a05e9cd5dbe346122f62bc91f61c88f3cb Mon Sep 17 00:00:00 2001 From: Manna Kong Date: Thu, 1 Jul 2021 16:19:14 -0500 Subject: [PATCH] everything but put and delete --- routes/index.js | 24 ++++++++++++++---------- views/trail-detail.pug | 6 +++++- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/routes/index.js b/routes/index.js index 65d53e0..438ad9f 100644 --- a/routes/index.js +++ b/routes/index.js @@ -73,17 +73,21 @@ router.put( }) ); -// router.delete('/:id(\\d+)', asyncHandler(async(req, res, next) => { -// const tweetId = req.params.id; -// const tweet = await Tweet.findByPk(tweetId); +router.delete('/trail/:id(\\d+)', asyncHandler(async(req, res, next) => { + const trailId = req.params.id; + const review = await db.Review.findAll({ where: { trailId }, include: "User" }) -// if (tweet) { -// await tweet.destroy(); -// res.status(201).end(); -// } else { -// next(tweetNotFound(tweetId)); -// } -// })); + await review.destroy(); +})); + +// router.delete('/trail/:id', function (req, res) { +// console.log("DELETE review") +// Review.findByIdAndRemove(req.params.id).then((review) => { +// res.redirect('/'); +// }).catch((err) => { +// console.log(err.message); +// }) +// }) router.post('/', (req, res) => { diff --git a/views/trail-detail.pug b/views/trail-detail.pug index 5b4242f..87fe51b 100644 --- a/views/trail-detail.pug +++ b/views/trail-detail.pug @@ -67,7 +67,11 @@ block content p(class="review-username")= `User: ${review.User.username}` p(class="review-text")= `${review.text}` p(class="review-date")= `Reviewed at: ${review.createdAt}` - button(type="submit" class="edit-btn") Edit Review + button(type="submit" class="edit-btn hi") Edit Review + p + form(action=`/trail/${trail.id}` method="delete" class="") + button(type="submit" class="delete-btn hi") Delete Review + //- input(type="hidden" class="edit-input") //- if (review.User.id === review.userId)