diff --git a/controllers/bookingController.js b/controllers/bookingController.js index 01ad1f7a77271c6feee8d4cea4be74da0d630fa5..bfe3816520503a2f02158c1777e0589ed4d004e5 100644 --- a/controllers/bookingController.js +++ b/controllers/bookingController.js @@ -119,18 +119,14 @@ exports.bookingSummary = async (req, res) => { if (!appointmentId) { return res.status(400).send("ไม่พบรหัสการจอง"); } - - // พยายามดึงข้อมูลการจองจากตารางหลัก + + // ดึงข้อมูลการจองจากทั้ง appointments และ appointment_history let appointment = await bookingModel.getAppointmentById(appointmentId); - // ถ้าไม่พบ ลองดึงจากตารางประวัติ (appointment_history) if (!appointment) { - appointment = await bookingModel.getAppointmentFromHistoryById(appointmentId); - if (!appointment) { - throw new Error("ไม่พบการจอง"); - } + throw new Error("ไม่พบการจองในฐานข้อมูล"); } - + const user = await bookingModel.getUserById(appointment.user_id); const service = await bookingModel.getServiceById(appointment.service_id); const slot = await bookingModel.getBookingSlotById(appointment.booking_slot_id);