From 07035be0bf2cba43553c30b8f80c84327dd1b96a Mon Sep 17 00:00:00 2001
From: Atiwit Pattanapukdee <65160394@go.buu.ac.th>
Date: Tue, 18 Mar 2025 23:29:27 +0700
Subject: [PATCH] Project Round 6

---
 models/tourModel.js | 20 +++++++++++---------
 views/edittour.ejs  |  1 -
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/models/tourModel.js b/models/tourModel.js
index ff73644..8f52124 100644
--- a/models/tourModel.js
+++ b/models/tourModel.js
@@ -14,21 +14,23 @@ class Tour {
       }
     }
     
-    // ค้นหาทัวร์โดยใช้ชื่อ
-    static async searchTours(query) {
+    static async searchTours(req, res) {
+      const query = req.query.query;
       try {
-
-        const [rows] = await pool.query('SELECT * FROM tours WHERE name LIKE ?', [`%${query}%`]);
-        // หากไม่มีทัวร์ที่ตรงกับคำค้นหา
-        if (rows.length === 0) {
-          return 'ไม่พบทัวร์ที่ตรงกับคำค้นหาของคุณ';
+        const tours = await Tour.searchTours(query);
+    
+        // ถ้าไม่มีทัวร์ในผลลัพธ์
+        if (tours.length === 0) {
+          console.log('ไม่พบทัวร์ที่ค้นหา');
         }
-        return rows;
+    
+        res.render('search', { tours });
       } catch (error) {
         console.error('Error searching tours:', error.message);
-        throw new Error('เกิดข้อผิดพลาดในการค้นหาทัวร์');
+        res.render('search', { tours: [] });
       }
     }
+    
 
     // สร้างทัวร์
     static async createTour(name, description, price, duration) {
diff --git a/views/edittour.ejs b/views/edittour.ejs
index 57ee9a3..90bbc56 100644
--- a/views/edittour.ejs
+++ b/views/edittour.ejs
@@ -9,7 +9,6 @@
 <body>
     <main>
         <h1>Edit Tour</h1>
-        <br>
         <form action="/edit/<%= tour.id %>" method="POST">
             <div>
                 <label for="tourName">Tour Name:</label>
-- 
GitLab