Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 0f18f2ed authored by 65160270's avatar 65160270
Browse files

update-address

parent 9453a15f
Branches
No related tags found
No related merge requests found
...@@ -46,8 +46,8 @@ router.get('/history', isAuthenticated, async (req, res) => { ...@@ -46,8 +46,8 @@ router.get('/history', isAuthenticated, async (req, res) => {
router.get('/detail/:orderId', isAuthenticated, async (req, res) => { router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
try { try {
const { orderId } = req.params; const { orderId } = req.params;
console.log(`Fetching order details for order ID: ${orderId}, Session ID: ${req.session.id}`);
// ดึงข้อมูลออเดอร์
const [orderResults] = await pool.query( const [orderResults] = await pool.query(
`SELECT id, total_amount, status, shipping_address, created_at `SELECT id, total_amount, status, shipping_address, created_at
FROM orders WHERE id = ? AND session_id = ?`, FROM orders WHERE id = ? AND session_id = ?`,
...@@ -55,12 +55,12 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => { ...@@ -55,12 +55,12 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
); );
if (orderResults.length === 0) { if (orderResults.length === 0) {
return res.status(404).send("ไม่พบคำสั่งซื้อ หรือไม่มีสิทธิ์เข้าถึง"); console.log("Order not found or user has no permission.");
return res.status(404).json({ message: "ไม่พบคำสั่งซื้อ หรือไม่มีสิทธิ์เข้าถึง" });
} }
const order = orderResults[0]; const order = orderResults[0];
// ดึงรายการสินค้าในออเดอร์
const [items] = await pool.query( const [items] = await pool.query(
`SELECT products.name, products.image_url, order_items.quantity, order_items.price `SELECT products.name, products.image_url, order_items.quantity, order_items.price
FROM order_items FROM order_items
...@@ -71,8 +71,8 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => { ...@@ -71,8 +71,8 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
res.render('order-detail', { order, items }); res.render('order-detail', { order, items });
} catch (error) { } catch (error) {
console.error(error); console.error("ERROR fetching order details:", error); // ดู Error Log
res.status(500).send('เกิดข้อผิดพลาดในการโหลดรายละเอียดคำสั่งซื้อ'); res.status(500).json({ message: "Something went wrong.", error: error.message });
} }
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment