From 891484d4a08e8869571c8aeb075f38809475f716 Mon Sep 17 00:00:00 2001 From: Atiwit Pattanapukdee <65160394@go.buu.ac.th> Date: Wed, 26 Mar 2025 16:57:35 +0700 Subject: [PATCH] Project Round 11 --- controllers/tourController.js | 2 +- models/tourModel.js | 47 +---------------------------------- views/booking.ejs | 46 ---------------------------------- views/bookinglist.ejs | 31 ----------------------- views/createtour.ejs | 9 +++++++ 5 files changed, 11 insertions(+), 124 deletions(-) delete mode 100644 views/booking.ejs delete mode 100644 views/bookinglist.ejs diff --git a/controllers/tourController.js b/controllers/tourController.js index adc47a7..248be51 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 307f4c9..0615621 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 11b1821..0000000 --- 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 594d7f2..0000000 --- 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 4a277a9..0c024d2 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> -- GitLab