diff --git a/models/tourModel.js b/models/tourModel.js index 1440f841689eb9d068bd285e90bebbeac5638153..ad7f7e34eb53572de1c637040882950500f695f6 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) {