Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit cd0bbbe7 authored by 65160014's avatar 65160014
Browse files

Initial commit

parent cd5edd8a
No related branches found
No related tags found
No related merge requests found
......@@ -119,15 +119,22 @@ exports.bookingSummary = async (req, res) => {
if (!appointmentId) {
return res.status(400).send("ไม่พบรหัสการจอง");
}
// ดึงข้อมูลการจอง
const appointment = await bookingModel.getAppointmentById(appointmentId);
// ดึงข้อมูลผู้ใช้
// พยายามดึงข้อมูลการจองจากตารางหลัก
let appointment = await bookingModel.getAppointmentById(appointmentId);
// ถ้าไม่พบ ลองดึงจากตารางประวัติ (appointment_history)
if (!appointment) {
appointment = await bookingModel.getAppointmentFromHistoryById(appointmentId);
if (!appointment) {
throw new Error("ไม่พบการจอง");
}
}
const user = await bookingModel.getUserById(appointment.user_id);
// ดึงข้อมูลบริการ
const service = await bookingModel.getServiceById(appointment.service_id);
// ดึงข้อมูล booking slot
const slot = await bookingModel.getBookingSlotById(appointment.booking_slot_id);
// Render หน้า bookingSummary.ejs พร้อมส่งข้อมูลที่ต้องการ
res.render('customer/bookingSummary', { appointment, user, service, slot });
} catch (error) {
console.error(error);
......@@ -135,6 +142,7 @@ exports.bookingSummary = async (req, res) => {
}
};
exports.getAllAppointmentPage = async (req, res) => {
try {
const user_id = req.session.userId;
......@@ -171,7 +179,7 @@ exports.cancelAppointment = async (req, res) => {
if (paymentStatus === 'Pending') {
// ย้ายข้อมูลไป appointment_history พร้อม `payment_status`
await bookingModel.addToHistory(appointmentId);
res.send('ยกเลิกการจองสำเร็จ และย้ายไปยังประวัติการนัดหมาย');
res.redirect('/customer/allAppointments');
} else {
res.status(400).send('ไม่สามารถยกเลิกการจองได้ เนื่องจากการชำระเงินเสร็จสมบูรณ์');
}
......
......@@ -89,8 +89,8 @@
<p><strong>ชื่อผู้จอง:</strong> <%= user.first_name %> <%= user.last_name %></p>
<p><strong>บริการ:</strong> <%= service.service_name %></p>
<p><strong>วันที่เข้ารับบริการ:</strong> <%= new Date(slot.date).toLocaleDateString('th-TH') %></p> <!-- Display only date -->
<p><strong>สถานะการจอง:</strong> <%= appointment.appointment_status %></p> <!-- Display appointment status -->
<p><strong>เวลาเข้ารับบริการ:</strong> <%= slot.start_time %></p>
<p><strong>สถานะการจอง:</strong> <%= appointment.appointment_status %></p> <!-- Display appointment status -->
<p class="alert-info">กรุณามาก่อนเวลา 10 นาที</p>
</div>
<div class="actions">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment