diff --git a/controllers/tourController.js b/controllers/tourController.js index 5ae9c6fd754609d77cf4de16968bc7fa5cefe1c9..a0355a9df00a63006ced449b1cd36e6029fb12e1 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 48d2a36a8976257d19e02d6e14c4652b503204b6..e966067ac1202a6918cf02e4268ea44aa22c8f81 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('เกิดข้อผิดพลาดในการสร้างทัวร์');