Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 891484d4 authored by 65160394's avatar 65160394
Browse files

Project Round 11

parent a7f54c84
No related branches found
No related tags found
No related merge requests found
const { User, Tour , Booking } = require('../models/tourModel');
const { User, Tour } = require('../models/tourModel');
const pool = require('../config/database');
exports.getTours = async (req, res) => {
......
......@@ -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 };
<!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>
<!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>
......@@ -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>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment