From e07c4097a5c2d5a9c1c8093fa0081a4b7e42c9a1 Mon Sep 17 00:00:00 2001
From: Atiwit Pattanapukdee <65160394@go.buu.ac.th>
Date: Tue, 18 Mar 2025 13:27:43 +0700
Subject: [PATCH] Project Round 3

---
 models/tourModel.js | 28 +++++++++++++++-------------
 1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/models/tourModel.js b/models/tourModel.js
index cd865a8..df8b710 100644
--- a/models/tourModel.js
+++ b/models/tourModel.js
@@ -14,19 +14,6 @@ class Tour {
       }
     }
   
-    // ดึงทัวร์ตาม ID
-    static async getTourById(id) {
-      try {
-        const [rows] = await pool.query('SELECT * FROM tours WHERE id = ?', [id]);
-        if (rows.length === 0) {
-          throw new Error('ไม่พบทัวร์ที่มี ID นี้');
-        }
-        return rows[0];
-      } catch (error) {
-        console.error('Error fetching tour by ID:', error);
-        throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์');
-      }
-    }
   
     // สร้างทัวร์
     static async createTour(name, description, price, duration) {
@@ -63,6 +50,21 @@ class Tour {
       }
     }
   
+    // ดึงทัวร์ตาม ID
+    static async getTourById(id) {
+      try {
+        console.log('Searching for tour with ID:', id); // เพิ่มบรรทัดนี้
+        const [rows] = await pool.query('SELECT * FROM tours WHERE id = ?', [id]);
+        if (rows.length === 0) {
+          throw new Error('ไม่พบทัวร์ที่มี ID นี้');
+        }
+        return rows[0];
+      } catch (error) {
+        console.error('Error fetching tour by ID:', error);
+        throw new Error('เกิดข้อผิดพลาดในการดึงข้อมูลทัวร์');
+      }
+    }
+
     // ลบทัวร์
     static async deleteTour(id) {
       const query = 'DELETE FROM tours WHERE id = ?';
-- 
GitLab