From 250f4ed60bd3bf2142823ed666bc135b714dcddb Mon Sep 17 00:00:00 2001 From: 65160381 <65160381@go.buu.ac.th> Date: Tue, 25 Mar 2025 04:26:28 +0700 Subject: [PATCH] 10.1 --- app.js | 4 ++++ public/{edit.html => edit-order.html} | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) rename public/{edit.html => edit-order.html} (82%) diff --git a/app.js b/app.js index eab7165..6197b11 100644 --- a/app.js +++ b/app.js @@ -53,6 +53,10 @@ pool.getConnection() // Static file serving app.use(express.static(path.join(__dirname, 'public'))); +app.get('/edit-order', (req, res) => { + res.sendFile(path.join(__dirname, 'public', 'edit-order.html')); +}); + // Session และ routes app.get('/', (req, res) => { if (req.session.user) { diff --git a/public/edit.html b/public/edit-order.html similarity index 82% rename from public/edit.html rename to public/edit-order.html index 6c6d723..f4ed37f 100644 --- a/public/edit.html +++ b/public/edit-order.html @@ -26,7 +26,15 @@ // Load order details from the API async function loadOrderDetails() { try { - const orderId = 1; // Replace with dynamic order ID + // Get orderId from the URL query string + const urlParams = new URLSearchParams(window.location.search); + const orderId = urlParams.get('orderId'); // Get orderId from URL parameter + + if (!orderId) { + alert('Order ID is missing in the URL'); + return; + } + const response = await fetch(`/api/orders/${orderId}`); const order = await response.json(); @@ -61,7 +69,15 @@ // Update order details async function updateOrder() { - const orderId = 1; // Replace with dynamic order ID + // Get orderId from the URL query string + const urlParams = new URLSearchParams(window.location.search); + const orderId = urlParams.get('orderId'); + + if (!orderId) { + alert('Order ID is missing in the URL'); + return; + } + const status = document.getElementById('order-status').value; const shippingAddress = document.getElementById('order-shipping-address').value; @@ -79,7 +95,7 @@ if (response.ok) { alert('Order updated successfully!'); - window.location.href = '/'; // Redirect to home page or orders page + window.location.href = '/orders'; // Redirect to orders page or home page } else { const errorMessage = await response.text(); alert('Error updating order: ' + errorMessage); -- GitLab