Gitlab@Informatics

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

Project Round 11

parent 891484d4
No related branches found
No related tags found
No related merge requests found
......@@ -100,30 +100,34 @@ class Tour {
if (!id) {
throw new Error("Tour ID is required");
}
// ตรวจสอบว่าทัวร์มีอยู่จริง
const checkQuery = 'SELECT * FROM tours WHERE id = ?';
const [tours] = await pool.execute(checkQuery, [id]);
if (tours.length === 0) {
throw new Error(`ไม่พบทัวร์ที่ต้องการลบ ID: ${id}`);
throw new Error("Tour not found");
}
// ลบ bookings ที่เกี่ยวข้องก่อน
const deleteBookingsQuery = 'DELETE FROM bookings WHERE tour_id = ?';
await pool.execute(deleteBookingsQuery, [id]);
// ลบ tour หลังจาก bookings ถูกลบแล้ว
const deleteTourQuery = 'DELETE FROM tours WHERE id = ?';
const [result] = await pool.execute(deleteTourQuery, [id]);
// แจ้งเตือนก่อนลบ
const userConfirmation = confirm(`คุณต้องการลบทัวร์ "${tours[0].name}" หรือไม่?`);
if (!userConfirmation) {
throw new Error("ลบทัวร์ถูกยกเลิก");
}
// ลบข้อมูลทัวร์จากฐานข้อมูล
const deleteQuery = 'DELETE FROM tours WHERE id = ?';
const [result] = await pool.execute(deleteQuery, [id]);
console.log("Delete result:", result);
return result;
} catch (error) {
console.error('Error deleting tour:', error);
throw new Error('เกิดข้อผิดพลาดในการลบทัวร์');
}
}
}
......
......@@ -13,7 +13,6 @@
<nav>
<% if (session && session.userId) { %>
<a href="/create" class="btn-create">Create Tour</a>
<a href="/create-booking" class="btn-create">Create Booking</a>
<% } %>
<form action="/search" method="GET" class="search-container">
<input type="text" name="query" placeholder="Search for tours..." required>
......@@ -21,7 +20,6 @@
</form>
<% if (session && session.userId) { %> <!-- ตรวจสอบ session -->
<a href="/bookinglist">Booking List</a>
<a href="/logout">Logout</a>
<% } else { %>
<a href="/login" class="login-btn">Login</a> <!-- ถ้ายังไม่ได้ login -->
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment