Gitlab@Informatics
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
prjcloud_65160270
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
65160270
prjcloud_65160270
Commits
f778f2cf
Commit
f778f2cf
authored
2 months ago
by
65160270
Browse files
Options
Downloads
Patches
Plain Diff
update-server
parent
1acf2ba8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
shop-routes/order.js
+21
-11
21 additions, 11 deletions
shop-routes/order.js
views/order-detail.ejs
+2
-2
2 additions, 2 deletions
views/order-detail.ejs
with
23 additions
and
13 deletions
shop-routes/order.js
+
21
−
11
View file @
f778f2cf
...
...
@@ -51,7 +51,7 @@ router.get('/history', isAuthenticated, async (req, res) => {
});
// แสดงรายละเอียดออเดอร์ (เฉพาะผู้ที่ Login)
router
.
get
(
'
/detail/:orderId
'
,
isAuthenticated
,
async
(
req
,
res
)
=>
{
router
.
get
(
'
/
order-
detail
s
/:orderId
'
,
isAuthenticated
,
async
(
req
,
res
)
=>
{
try
{
if
(
!
req
.
session
.
id
)
{
return
res
.
status
(
400
).
json
({
message
:
"
Session ID not found. Please login again.
"
});
...
...
@@ -60,14 +60,10 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
const
{
orderId
}
=
req
.
params
;
console
.
log
(
`🔹 Fetching order ID:
${
orderId
}
, Session ID:
${
req
.
session
.
id
}
`
);
// ดึงข้อมูลคำสั่งซื้อ
const
[
orderResults
]
=
await
pool
.
query
(
`SELECT orders.id, orders.total_amount, orders.status, orders.shipping_address, orders.created_at,
GROUP_CONCAT(CONCAT(products.name, ' x ', order_items.quantity, ' (฿', order_items.price, ')') SEPARATOR ', ') as items_detail
FROM orders
JOIN order_items ON orders.id = order_items.order_id
JOIN products ON order_items.product_id = products.id
WHERE orders.id = ? AND orders.session_id = ?
GROUP BY orders.id`
,
`SELECT id, total_amount, status, shipping_address, created_at
FROM orders WHERE id = ? AND session_id = ?`
,
[
orderId
,
req
.
session
.
id
]
);
...
...
@@ -76,8 +72,22 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
return
res
.
status
(
404
).
json
({
message
:
"
ไม่พบคำสั่งซื้อ หรือไม่มีสิทธิ์เข้าถึง
"
});
}
console
.
log
(
"
Order found:
"
,
orderResults
[
0
]);
res
.
json
(
orderResults
[
0
]);
// ดึงรายการสินค้าใน order_items
const
[
orderItems
]
=
await
pool
.
query
(
`SELECT order_items.order_id, order_items.product_id, products.name,
order_items.quantity, order_items.price
FROM order_items
JOIN products ON order_items.product_id = products.id
WHERE order_items.order_id = ?`
,
[
orderId
]
);
console
.
log
(
"
Order Items:
"
,
orderItems
);
res
.
json
({
order
:
orderResults
[
0
],
items
:
orderItems
});
}
catch
(
error
)
{
console
.
error
(
"
Error fetching order:
"
,
error
);
res
.
status
(
500
).
json
({
message
:
"
Something went wrong.
"
,
error
:
error
.
message
});
...
...
@@ -85,7 +95,7 @@ router.get('/detail/:orderId', isAuthenticated, async (req, res) => {
});
// อัปเดตที่อยู่จัดส่งของคำสั่งซื้อ
router
.
put
(
'
/detail/:orderId
'
,
isAuthenticated
,
async
(
req
,
res
)
=>
{
router
.
put
(
'
/
order-
detail
s
/:orderId
'
,
isAuthenticated
,
async
(
req
,
res
)
=>
{
try
{
console
.
log
(
"
Updating order...
"
);
console
.
log
(
"
Session ID:
"
,
req
.
session
.
id
);
...
...
This diff is collapsed.
Click to expand it.
views/order-detail.ejs
+
2
−
2
View file @
f778f2cf
...
...
@@ -31,11 +31,11 @@
<tbody>
<% items.forEach(item => { %>
<tr>
<td><%= item.order_id %></td>
<td><%= item.order_id %></td>
<!-- จะแสดง Order ID ได้แล้ว -->
<td><%= item.product_id %></td>
<td><%= item.name %></td>
<td><%= item.quantity %></td>
<td>฿<%= item.price.toFixed(2) %></td>
<td>฿<%=
Number(
item.price
)
.toFixed(2) %></td>
<!-- ป้องกัน TypeError -->
</tr>
<% }) %>
</tbody>
...
...
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