From f90f607eebf387f76b658a9aa0b8f0029d2273df Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Thu, 20 Mar 2025 22:51:31 +0700 Subject: [PATCH] Project Round 9 --- controllers/tourController.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/controllers/tourController.js b/controllers/tourController.js index e098cd7..488b1e3 100644 --- a/controllers/tourController.js +++ b/controllers/tourController.js @@ -256,16 +256,22 @@ exports.postEditTour = async (req, res) => { exports.deleteTour = async (req, res) => { try { - console.log("Tour ID ที่ต้องการลบ:", req.params.id); - await Tour.deleteTour(req.params.id); - res.redirect('/tours'); // กลับไปที่หน้ารายการทัวร์ + const tourId = req.params.id; + console.log("Request to delete tour ID:", tourId); // ตรวจสอบค่า ID + + if (!tourId) { + return res.status(400).send("Tour ID is required"); + } + + await Tour.deleteTour(tourId); + res.redirect('/tourlist'); // หรือส่ง JSON กลับ } catch (error) { - console.error(error.message); res.status(500).send(error.message); } }; + //ค้นหาทัวร์ exports.searchTours = async (req, res) => { try { -- GitLab