From 536707d9353dc11252248be3d93376108d09ebaf Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Thu, 20 Mar 2025 18:41:56 +0700 Subject: [PATCH] Project Round 8 --- models/tourModel.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/models/tourModel.js b/models/tourModel.js index 1440f84..ad7f7e3 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -58,22 +58,20 @@ class Tour { // อัปเดตทัวร์ - static async updateTour(id, tourData) { + static async updateTour(userId, tourData) { const { name, description, price, duration } = tourData; - - // ตรวจสอบข้อมูล - if (!name || !price || !duration) { - throw new Error('ข้อมูลไม่ครบถ้วน กรุณากรอกข้อมูลให้ครบถ้วน'); - } - - const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? WHERE id = ?'; + const query = 'UPDATE tours SET name = ?, description = ?, price = ?, duration = ? WHERE userId = ?'; + try { - await pool.execute(query, [name, description, price, duration, id]); + const [results] = await pool.execute(query, [name, description, price, duration, userId]); + console.log('✅ Update results:', results); + return results; } catch (error) { - console.error('Error updating tour:', error); - throw new Error('เกิดข้อผิดพลาดในการอัปเดตทัวร์'); + console.error('Error updating tour:', error); // ตรวจสอบข้อผิดพลาดในฐานข้อมูล + throw error; } } + // ดึงทัวร์ตาม ID static async getTourById(id) { -- GitLab