diff --git a/controllers/tourController.js b/controllers/tourController.js index adc47a7e7276b33bc275fb6a74e9106f40f1dac8..248be51412595bd521a4841c5ddb6b6315eccad3 100644 --- a/controllers/tourController.js +++ b/controllers/tourController.js @@ -1,4 +1,4 @@ -const { User, Tour , Booking } = require('../models/tourModel'); +const { User, Tour } = require('../models/tourModel'); const pool = require('../config/database'); exports.getTours = async (req, res) => { diff --git a/models/tourModel.js b/models/tourModel.js index 307f4c975b8ef5764df682503769af87f967e8a8..06156211cee3c600d0b6ad81d863e6fbf3463a19 100644 --- a/models/tourModel.js +++ b/models/tourModel.js @@ -161,49 +161,4 @@ class User { } } -class Booking { - // ดึงรายการจองของผู้ใช้ - static async getUserBookings(userId) { - const query = ` - SELECT b.id, t.name AS tour_name, t.price, b.booking_date - FROM bookings b - JOIN tours t ON b.tour_id = t.id - WHERE b.user_id = ? - ORDER BY b.id ASC - `; - try { - const [rows] = await pool.query(query, [userId]); - return rows; // คืนค่ารายการจองทั้งหมด - } catch (error) { - console.error('Error fetching user bookings:', error); - throw new Error('Unable to retrieve user bookings'); - } - } - - // ทำการจองทัวร์ - static async createBooking(userId, tourId) { - const query = 'INSERT INTO bookings (user_id, tour_id) VALUES (?, ?)'; - try { - const [result] = await pool.execute(query, [userId, tourId]); - return result; // คืนค่าผลลัพธ์จากการจอง - } catch (error) { - console.error('Error creating booking:', error); - throw new Error('Error creating booking'); - } - } - - // ลบการจอง - static async deleteBooking(bookingId) { - const query = 'DELETE FROM bookings WHERE id = ?'; - try { - const [result] = await pool.execute(query, [bookingId]); - return result; // คืนค่าผลลัพธ์จากการลบการจอง - } catch (error) { - console.error('Error deleting booking:', error); - throw new Error('Error deleting booking'); - } - } -} - - -module.exports = { User, Tour, Booking }; +module.exports = { User, Tour }; diff --git a/views/booking.ejs b/views/booking.ejs deleted file mode 100644 index 11b18215d8eac56d61dda69fedab27d808e6193d..0000000000000000000000000000000000000000 --- a/views/booking.ejs +++ /dev/null @@ -1,46 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>Book a Tour</title> - <link rel="stylesheet" href="/css/booking.css"> -</head> -<body> - <div class="container"> - <h1>Tour Booking</h1> - - <!-- แสดงรายการทัวร์ --> - <div class="tour-list"> - <h2>Available Tours</h2> - <ul> - <% tours.forEach(function(tour) { %> - <li> - <strong><%= tour.name %></strong><br> - <%= tour.description %><br> - ราคา: <%= tour.price %> บาท<br> - ระยะเวลา: <%= tour.duration %> วัน<br> - </li> - <% }); %> - </ul> - </div> - - <!-- ช่องกรอกข้อมูลจอง --> - <div class="booking-form"> - <h2>จอง Tour</h2> - <form action="/create-booking" method="POST"> - <label for="tour-id">เลือก Tour</label> - <select id="tour-id" name="tour-id" required> - <option value="" disabled selected>Select a Tour</option> - <% tours.forEach(function(tour) { %> - <option value="<%= tour.id %>"><%= tour.name %></option> - <% }); %> - </select> - - <button type="submit">Book Now</button> - </form> - </div> - </div> - -</body> -</html> diff --git a/views/bookinglist.ejs b/views/bookinglist.ejs deleted file mode 100644 index 594d7f206db70696e5b017322214dfd7fea39068..0000000000000000000000000000000000000000 --- a/views/bookinglist.ejs +++ /dev/null @@ -1,31 +0,0 @@ -<!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <title>bookinglist</title> - <link rel="stylesheet" href="/css/booklist.css"> -</head> -<body> - <h1>bookinglist</h1> - <table border="1"> - <thead> - <tr> - <th>Booking ID</th> - <th>Booking User</th> - <th>Tour Title</th> - </tr> - </thead> - <tbody> - <% bookings.forEach(booking => { %> - <tr> - <td><%= booking.booking_id %></td> <!-- booking_id --> - <td><%= booking.user_name %></td> <!-- ชื่อผู้จอง --> - <td><%= booking.tour_name %></td> <!-- tour_title --> - </tr> - <% }) %> - </tbody> - </table> - <a href="/" class="btn-back">ย้อนกลับ</a> -</body> -</html> diff --git a/views/createtour.ejs b/views/createtour.ejs index 4a277a98a5e5490bf573a544da412a50f45c6674..0c024d2256fd5efa729fe7600fdb6b6a00dd71c0 100644 --- a/views/createtour.ejs +++ b/views/createtour.ejs @@ -27,6 +27,15 @@ <label for="tourDuration">ระยะเวลา (วัน):</label> <input type="text" id="tourDuration" name="duration" required> </div> + <div> + <label for="tourCompany">บริษัท:</label> + <select id="tourCompany" name="company_id" required> + <option value="" re>เลือกบริษัท</option> + <option value="1">Amazing Travel</option> + <option value="2">Wonderful Tours</option> + <option value="3">Explore Asia</option> + </select> + </div> <button type="submit">สร้างโปรแกรม Tour</button> </form> </main>