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
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
65160270
prjcloud_65160270
Commits
b6083c10
Commit
b6083c10
authored
3 months ago
by
65160270
Browse files
Options
Downloads
Patches
Plain Diff
update-address
parent
90b60b2d
Branches
Branches containing commit
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
+7
-6
7 additions, 6 deletions
shop-routes/order.js
views/order-details.ejs
+33
-1
33 additions, 1 deletion
views/order-details.ejs
with
40 additions
and
7 deletions
shop-routes/order.js
+
7
−
6
View file @
b6083c10
...
...
@@ -144,8 +144,9 @@ router.post('/create', isAuthenticated, async (req, res) => {
});
// อัปเดตที่อยู่จัดส่งของออเดอร์
router
.
post
(
'
/update-address
'
,
isAuthenticated
,
async
(
req
,
res
)
=>
{
const
{
orderId
,
newAddress
}
=
req
.
body
;
router
.
put
(
'
/update-address/:orderId
'
,
isAuthenticated
,
async
(
req
,
res
)
=>
{
const
{
shipping_address
}
=
req
.
body
;
const
orderId
=
req
.
params
.
orderId
;
try
{
// ตรวจสอบว่าออเดอร์เป็นของผู้ใช้ปัจจุบัน
...
...
@@ -155,19 +156,19 @@ router.post('/update-address', isAuthenticated, async (req, res) => {
);
if
(
order
.
length
===
0
)
{
return
res
.
status
(
404
).
send
(
'
Order not found or unauthorized
'
);
return
res
.
status
(
404
).
json
({
success
:
false
,
message
:
'
Order not found or unauthorized
'
}
);
}
// อัปเดตที่อยู่จัดส่ง
await
pool
.
query
(
'
UPDATE orders SET shipping_address = ? WHERE id = ?
'
,
[
newA
ddress
,
orderId
]
[
shipping_a
ddress
,
orderId
]
);
res
.
send
(
'
Shipping address updated successfully
'
);
res
.
json
({
success
:
true
,
message
:
'
Shipping address updated successfully
'
}
);
}
catch
(
error
)
{
console
.
error
(
error
);
res
.
status
(
500
).
send
(
'
Error updating shipping address
'
);
res
.
status
(
500
).
json
({
success
:
false
,
message
:
'
Error updating shipping address
'
}
);
}
});
...
...
This diff is collapsed.
Click to expand it.
views/order-details.ejs
+
33
−
1
View file @
b6083c10
...
...
@@ -11,7 +11,11 @@
<div class="info-section">
<h3>Shipping Address</h3>
<p><%= order.shipping_address %></p>
<p id="currentAddress"><%= order.shipping_address %></p>
<!-- Input สำหรับแก้ไขที่อยู่ -->
<input type="text" id="newAddress" placeholder="Enter new address">
<button onclick="updateAddress(<%= order.id %>)">Update Address</button>
</div>
</div>
...
...
@@ -37,4 +41,32 @@
<a href="/" class="continue-shopping">Continue Shopping</a>
</div>
</div>
<script>
function updateAddress(orderId) {
const newAddress = document.getElementById("newAddress").value;
if (!newAddress.trim()) {
alert("Please enter a valid address.");
return;
}
fetch(`/order/update-address/${orderId}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ shipping_address: newAddress })
})
.then(response => response.json())
.then(data => {
if (data.success) {
document.getElementById("currentAddress").innerText = newAddress;
alert("Address updated successfully!");
} else {
alert("Failed to update address.");
}
})
.catch(error => console.error("Error:", error));
}
</script>
<%- include('partials/footer') %>
\ No newline at end of file
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