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

---
 controllers/tourController.js | 10 +++++++++-
 public/css/search.css         | 15 +++++++++++++++
 views/search.ejs              |  2 +-
 3 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/controllers/tourController.js b/controllers/tourController.js
index 48091bc..3579002 100644
--- a/controllers/tourController.js
+++ b/controllers/tourController.js
@@ -214,8 +214,16 @@ exports.searchTours = async (req, res) => {
   try {
     const searchQuery = req.query.query;
     const tours = await Tour.searchTours(searchQuery);
+
+    // ตรวจสอบว่าผลลัพธ์จาก Tour.searchTours เป็นอาร์เรย์หรือไม่
+    if (!Array.isArray(tours)) {
+      console.log('ผลลัพธ์จาก searchTours ไม่ใช่ Array:', tours);
+      return res.render('search', { tours: [], session: req.session }); // ส่งอาร์เรย์ว่างไปหากไม่ใช่ Array
+    }
+
     res.render('search', { tours, session: req.session });
   } catch (error) {
+    console.error('Error searching tours:', error);
     res.status(500).send("Error searching tours");
   }
-};
\ No newline at end of file
+};
diff --git a/public/css/search.css b/public/css/search.css
index 3be59fa..59c7918 100644
--- a/public/css/search.css
+++ b/public/css/search.css
@@ -71,4 +71,19 @@ body {
   a.back-home:hover {
     color: #0056b3;
   }
+
+  .button {
+    padding: 10px 20px;
+    background-color: #0073e6;
+    color: white;
+    border: none;
+    border-radius: 5px;
+    cursor: pointer;
+    font-size: 16px;
+    transition: background-color 0.3s;
+  }
+  
+  .button:hover {
+    background-color: #005bb5;
+  }
   
\ No newline at end of file
diff --git a/views/search.ejs b/views/search.ejs
index ec60cf8..8330afb 100644
--- a/views/search.ejs
+++ b/views/search.ejs
@@ -13,4 +13,4 @@
   <% } %>
 </ul>
 
-<a href="/">Back to Home</a>
+<a href="/" class="button">Back to Home</a>
-- 
GitLab