From 41c7e297a0415276544e0975f6dfd6de67d3b6ff Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Thu, 20 Mar 2025 23:03:36 +0700 Subject: [PATCH] Project Round 9 --- controllers/tourController.js | 11 ----------- models/tourModel.js | 8 +------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/controllers/tourController.js b/controllers/tourController.js index 5ae9c6f..a0355a9 100644 --- a/controllers/tourController.js +++ b/controllers/tourController.js @@ -209,16 +209,6 @@ exports.getEditTour = async (req, res) => { if (!tour) { return res.status(404).send('ไม่พบข้อมูลทัวร์'); } - - // ตรวจสอบว่ามี user_id หรือไม่ - if (!tour.user_id) { - return res.status(500).send('ข้อมูลทัวร์ไม่สมบูรณ์'); - } - - if (tour.user_id !== req.session.userId) { - return res.status(403).send('คุณไม่มีสิทธิ์แก้ไขทัวร์นี้'); - } - res.render('edittour', { tour }); } catch (error) { console.error("Error fetching tour:", error); @@ -227,7 +217,6 @@ exports.getEditTour = async (req, res) => { }; - exports.postEditTour = async (req, res) => { const { name, description, price, duration } = req.body; const tourId = req.params.id; // ดึง id จาก URL parameters diff --git a/models/tourModel.js b/models/tourModel.js index 48d2a36..e966067 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -40,16 +40,10 @@ class Tour { throw new Error('ข้อมูลไม่ครบถ้วน กรุณากรอกข้อมูลให้ครบถ้วน'); } - // ตรวจสอบว่า userId เป็นตัวเลขหรือไม่ - const validUserId = parseInt(userId, 10); - if (isNaN(validUserId)) { - throw new Error('User ID ไม่ถูกต้อง'); - } - const query = 'INSERT INTO tours (name, description, price, duration, userId) VALUES (?, ?, ?, ?, ?)'; try { // บันทึกทัวร์พร้อมกับ userId ที่สร้างทัวร์ - await pool.execute(query, [name, description, price, duration, validUserId]); + await pool.execute(query, [name, description, price, duration, userId]); } catch (error) { console.error('Error creating tour:', error); throw new Error('เกิดข้อผิดพลาดในการสร้างทัวร์'); -- GitLab