Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
final-exam
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
final-exam
Commits
95bc0080
Commit
95bc0080
authored
Oct 03, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
show order list on user
parent
5d635a06
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
150 additions
and
1 deletion
+150
-1
OrderController.js
app/controllers/OrderController.js
+15
-0
user.js
app/routes/user.js
+1
-0
Navbar.js
src/components/Navbar.js
+1
-1
order.js
src/pages/order.js
+133
-0
No files found.
app/controllers/OrderController.js
View file @
95bc0080
...
@@ -2,6 +2,21 @@ import { Request, Response } from "express";
...
@@ -2,6 +2,21 @@ import { Request, Response } from "express";
import
db
from
"../models/prismaClient"
;
import
db
from
"../models/prismaClient"
;
const
OrderController
=
{
const
OrderController
=
{
/**
*
* @param {Request} req
* @param {Response} res
*/
async
index
(
req
,
res
)
{
try
{
const
order
=
await
db
.
order
.
findMany
({
where
:
{
user_id
:
Number
(
req
.
user
.
id
)
},
});
res
.
json
(
order
)
}
catch
(
err
)
{
res
.
json
({
status
:
100
,
message
:
"server found some error"
});
}
},
/**
/**
*
*
* @param {Request} req
* @param {Request} req
...
...
app/routes/user.js
View file @
95bc0080
...
@@ -12,6 +12,7 @@ UserRouter.get("/cart", CartController.index);
...
@@ -12,6 +12,7 @@ UserRouter.get("/cart", CartController.index);
UserRouter
.
post
(
"/cart"
,
CartController
.
create
);
UserRouter
.
post
(
"/cart"
,
CartController
.
create
);
UserRouter
.
delete
(
"/cart"
,
CartController
.
delete
);
UserRouter
.
delete
(
"/cart"
,
CartController
.
delete
);
UserRouter
.
get
(
"/order"
,
OrderController
.
index
);
UserRouter
.
post
(
"/order"
,
OrderController
.
create
);
UserRouter
.
post
(
"/order"
,
OrderController
.
create
);
export
default
UserRouter
;
export
default
UserRouter
;
src/components/Navbar.js
View file @
95bc0080
...
@@ -173,7 +173,7 @@ function Navbar(props) {
...
@@ -173,7 +173,7 @@ function Navbar(props) {
aria
-
label
=
"show 4 new mails"
aria
-
label
=
"show 4 new mails"
color
=
"inherit"
color
=
"inherit"
>
>
<
Badge
badgeContent
=
{
2
}
color
=
"error"
>
<
Badge
color
=
"error"
>
<
ShoppingBag
/>
<
ShoppingBag
/>
<
/Badge
>
<
/Badge
>
<
/IconButton
>
<
/IconButton
>
...
...
src/pages/order.js
0 → 100644
View file @
95bc0080
import
{
Box
,
Button
,
Paper
,
Table
,
TableBody
,
TableCell
,
TableHead
,
TableRow
,
}
from
"@mui/material"
;
import
React
,
{
useContext
,
useEffect
,
useState
}
from
"react"
;
import
{
CartContext
,
UserContext
,
WishlistContext
}
from
"./_app"
;
import
{
useRouter
}
from
"next/router"
;
import
axios
from
"axios"
;
import
PopupAlert
from
"@/components/PopupAlert"
;
import
Head
from
"next/head"
;
import
{
ShoppingBag
}
from
"@mui/icons-material"
;
import
ConfirmOrder
from
"@/components/order/ConfirmOrder"
;
export
default
function
Order
()
{
const
user
=
useContext
(
UserContext
);
const
cart
=
useContext
(
CartContext
);
const
[
products
,
setProducts
]
=
useState
([]);
const
[
message
,
setMessage
]
=
useState
({
error
:
false
,
message
:
""
});
const
[
orderState
,
setOrderState
]
=
useState
(
false
);
const
router
=
useRouter
();
const
[
orderList
,
setOrderList
]
=
useState
([]);
const
[
CartProduct
,
setCartProduct
]
=
useState
([]);
const
fetchOrder
=
async
()
=>
{
if
(
!
user
.
value
?.
token
)
return
;
let
response
=
await
axios
.
get
(
"/api/u/order"
,
{
headers
:
{
token
:
user
.
value
.
token
},
});
setOrderList
(
response
.
data
);
console
.
log
(
response
.
data
);
};
const
fetchProduct
=
async
()
=>
{
try
{
let
product
=
await
axios
.
get
(
"/api/product"
);
setProducts
(
product
.
data
);
}
catch
(
err
)
{}
};
useEffect
(()
=>
{
fetchProduct
();
},
[]);
useEffect
(()
=>
{
fetchOrder
();
},
[
user
]);
useEffect
(()
=>
{
setCartProduct
(
cart
.
value
.
map
(
(
ct
)
=>
products
.
filter
((
pd
)
=>
pd
.
id
===
ct
.
product_id
)[
0
]
)
);
},
[
cart
,
products
]);
return
(
<>
<
Head
>
<
title
>
คำสั่งซื้อ
|
OpenShop
<
/title
>
<
/Head
>
<
Box
>
<
PopupAlert
open
=
{
!!
message
.
message
.
length
}
isError
=
{
message
.
error
}
message
=
{
message
.
message
}
/
>
<
Paper
sx
=
{{
p
:
1
,
overflowX
:
"scroll"
}}
>
{
orderList
.
length
>
0
?
(
<
Box
>
<
Table
>
<
TableHead
>
<
TableRow
>
{[
"id"
,
"ราคาทั้งหมด"
,
"จำนวนสินค้า"
,
"ค่าส่ง"
,
"ชำระเงิน"
,
"การจัดส่ง"
,
].
map
((
label
,
idx
)
=>
(
<
TableCell
key
=
{
idx
}
>
{
label
}
<
/TableCell
>
))}
<
/TableRow
>
<
/TableHead
>
<
TableBody
>
{
orderList
.
map
(
(
order
,
idx
)
=>
order
&&
(
<
TableRow
key
=
{
idx
}
>
<
TableCell
>
{
order
.
id
}
<
/TableCell
>
<
TableCell
>
<
Box
color
=
"orangered"
>
$
{
Number
(
order
.
total_price
).
toLocaleString
()}
<
/Box
>
<
/TableCell
>
<
TableCell
>
{
order
.
product_count
}
<
/TableCell
>
<
TableCell
>
{
order
.
shipping_price
}
<
/TableCell
>
<
TableCell
>
<
Box
color
=
{
order
.
pay_status
?
"green"
:
"red"
}
>
{
order
.
pay_status
?
"ชำระเงินแล้ว"
:
"ยังไม่ชำระเงิน"
}
<
/Box
>
<
/TableCell
>
<
TableCell
>
<
Box
color
=
{
order
.
send_status
?
"green"
:
"red"
}
>
{
order
.
send_status
?
"ส่งแล้ว"
:
"ยังไม่จัดส่ง"
}
<
/Box
>
<
/TableCell
>
<
/TableRow
>
)
)}
<
/TableBody
>
<
/Table
>
<
/Box
>
)
:
(
<
div
className
=
"text-center"
>
{
user
.
value
?.
token
?
"รายการว่างเปล่า"
:
"คุณยังไม่ได้เข้าสู่ระบบ"
}
<
/div
>
)}
<
/Paper
>
<
/Box
>
<
/
>
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment