Gitlab@Informatics

Skip to content
Snippets Groups Projects
Commit 90b60b2d authored by 65160270's avatar 65160270
Browse files

update-address

parent e7dee9d5
No related branches found
No related tags found
No related merge requests found
......@@ -143,6 +143,34 @@ router.post('/create', isAuthenticated, async (req, res) => {
}
});
// อัปเดตที่อยู่จัดส่งของออเดอร์
router.post('/update-address', isAuthenticated, async (req, res) => {
const { orderId, newAddress } = req.body;
try {
// ตรวจสอบว่าออเดอร์เป็นของผู้ใช้ปัจจุบัน
const [order] = await pool.query(
'SELECT * FROM orders WHERE id = ? AND session_id = ?',
[orderId, req.session.id]
);
if (order.length === 0) {
return res.status(404).send('Order not found or unauthorized');
}
// อัปเดตที่อยู่จัดส่ง
await pool.query(
'UPDATE orders SET shipping_address = ? WHERE id = ?',
[newAddress, orderId]
);
res.send('Shipping address updated successfully');
} catch (error) {
console.error(error);
res.status(500).send('Error updating shipping address');
}
});
router.get('/confirmation', (req, res) => {
res.render('confirmation');
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment