Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
project-melon
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160381
project-melon
Commits
7b2f9201
Commit
7b2f9201
authored
1 month ago
by
65160381
Browse files
Options
Downloads
Patches
Plain Diff
10
parent
b29dcc51
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#629
passed with warnings
1 month ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.js
+26
-0
26 additions, 0 deletions
app.js
public/edit.html
+97
-0
97 additions, 0 deletions
public/edit.html
with
123 additions
and
0 deletions
app.js
+
26
−
0
View file @
7b2f9201
...
...
@@ -149,6 +149,32 @@ app.post('/api/products', async (req, res) => {
}
});
// Get order details by order ID
app
.
get
(
'
/api/orders/:orderId
'
,
(
req
,
res
)
=>
{
const
orderId
=
parseInt
(
req
.
params
.
orderId
);
const
order
=
orders
.
find
(
o
=>
o
.
order_id
===
orderId
);
if
(
order
)
{
res
.
json
(
order
);
}
else
{
res
.
status
(
404
).
send
(
'
Order not found
'
);
}
});
// Update order details by order ID
app
.
put
(
'
/api/orders/:orderId
'
,
(
req
,
res
)
=>
{
const
orderId
=
parseInt
(
req
.
params
.
orderId
);
const
{
status
,
shipping_address
}
=
req
.
body
;
const
order
=
orders
.
find
(
o
=>
o
.
order_id
===
orderId
);
if
(
order
)
{
order
.
status
=
status
||
order
.
status
;
order
.
shipping_address
=
shipping_address
||
order
.
shipping_address
;
res
.
send
(
'
Order updated successfully
'
);
}
else
{
res
.
status
(
404
).
send
(
'
Order not found
'
);
}
});
// ตัวอย่างของการดึงข้อมูลสินค้าใน Node.js (Express)
app
.
get
(
'
/api/products
'
,
async
(
req
,
res
)
=>
{
const
searchQuery
=
req
.
query
.
search
||
''
;
// รับคำค้นจาก query string
...
...
This diff is collapsed.
Click to expand it.
public/edit.html
0 → 100644
+
97
−
0
View file @
7b2f9201
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
Edit Order
</title>
<link
rel=
"stylesheet"
href=
"styles/home.css"
>
</head>
<body>
<header>
<h1>
Edit Your Order
</h1>
</header>
<div
id=
"order-details"
>
<!-- Order details will be dynamically loaded here -->
</div>
<button
id=
"update-order-button"
onclick=
"updateOrder()"
>
Update Order
</button>
<footer>
<p>
©
2025 ASA
</p>
</footer>
<script>
// Load order details from the API
async
function
loadOrderDetails
()
{
try
{
const
orderId
=
1
;
// Replace with dynamic order ID
const
response
=
await
fetch
(
`/api/orders/
${
orderId
}
`
);
const
order
=
await
response
.
json
();
const
orderDetailsContainer
=
document
.
getElementById
(
'
order-details
'
);
orderDetailsContainer
.
innerHTML
=
`
<h2>Order ID:
${
order
.
order_id
}
</h2>
<div>
<label for="order-status">Order Status:</label>
<select id="order-status">
<option value="pending"
${
order
.
status
===
'
pending
'
?
'
selected
'
:
''
}
>Pending</option>
<option value="shipped"
${
order
.
status
===
'
shipped
'
?
'
selected
'
:
''
}
>Shipped</option>
<option value="delivered"
${
order
.
status
===
'
delivered
'
?
'
selected
'
:
''
}
>Delivered</option>
</select>
</div>
<div>
<label for="order-shipping-address">Shipping Address:</label>
<input type="text" id="order-shipping-address" value="
${
order
.
shipping_address
}
" required>
</div>
<div>
<label for="order-products">Products:</label>
<ul id="order-products">
${
order
.
products
.
map
(
product
=>
`
<li>
${
product
.
name
}
- $
${
product
.
price
}
x
${
product
.
quantity
}
</li>
`
).
join
(
''
)}
</ul>
</div>
`
;
}
catch
(
error
)
{
console
.
error
(
'
Error loading order details:
'
,
error
);
}
}
// Update order details
async
function
updateOrder
()
{
const
orderId
=
1
;
// Replace with dynamic order ID
const
status
=
document
.
getElementById
(
'
order-status
'
).
value
;
const
shippingAddress
=
document
.
getElementById
(
'
order-shipping-address
'
).
value
;
try
{
const
response
=
await
fetch
(
`/api/orders/
${
orderId
}
`
,
{
method
:
'
PUT
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
},
body
:
JSON
.
stringify
({
status
:
status
,
shipping_address
:
shippingAddress
})
});
if
(
response
.
ok
)
{
alert
(
'
Order updated successfully!
'
);
window
.
location
.
href
=
'
/
'
;
// Redirect to home page or orders page
}
else
{
const
errorMessage
=
await
response
.
text
();
alert
(
'
Error updating order:
'
+
errorMessage
);
}
}
catch
(
error
)
{
console
.
error
(
'
Error updating order:
'
,
error
);
alert
(
'
Error updating order
'
);
}
}
// Load order details when page loads
window
.
onload
=
loadOrderDetails
;
</script>
</body>
</html>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment