From 4ac30184af9ef489b8064cf1dd26dd50ae5b78d5 Mon Sep 17 00:00:00 2001
From: Atiwit Pattanapukdee <65160394@go.buu.ac.th>
Date: Thu, 20 Mar 2025 21:34:08 +0700
Subject: [PATCH] Project Round 9

---
 controllers/tourController.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/controllers/tourController.js b/controllers/tourController.js
index 37c73d3..0e025d1 100644
--- a/controllers/tourController.js
+++ b/controllers/tourController.js
@@ -310,12 +310,15 @@ exports.createBooking = async (req, res) => {
       return res.status(404).send('Tour not found.');
     }
 
-    // ทำการจองทัวร์
-    await Booking.createBooking(userId, tourId);
-    res.redirect('/my-bookings');  // หลังจากจองเสร็จ เปลี่ยนเส้นทางไปยังหน้าการจองของผู้ใช้
+    // ทำการจองทัวร์ (บันทึกการจองในตาราง bookings)
+    const bookingQuery = 'INSERT INTO bookings (user_id, tour_id) VALUES (?, ?)';
+    await pool.execute(bookingQuery, [userId, tourId]);
+
+    // หลังจากบันทึกการจองสำเร็จแล้ว, ส่งผู้ใช้กลับไปที่หน้ารายการจอง
+    res.redirect('/my-bookings');
   } catch (error) {
     console.error('Error creating booking:', error.message);
-    res.status(500).send('Internal Server Error');
+    res.status(500).send('เกิดข้อผิดพลาดในการจองทัวร์');
   }
 };
 
-- 
GitLab