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
f147ee7d
Commit
f147ee7d
authored
Oct 05, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
admin can update sending status
parent
a499bc97
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
13 deletions
+74
-13
README.md
README.md
+1
-1
AdminOrderController.js
app/controllers/AdminOrderController.js
+20
-0
admin.js
app/routes/admin.js
+1
-0
order.js
src/pages/admin/order.js
+52
-12
No files found.
README.md
View file @
f147ee7d
...
...
@@ -22,7 +22,7 @@ final exam of web programming with ~~PHP~~ **JavaScript** and using ~~Laravel~~
-
migration
-
`npx prisma migrate dev`
เพื่อทำการ migrate ฐานข้อมูล
-
*
หาก error อาจจะต้องทำการ upgrade mysql โดย
-
รันไฟล์ชื่อ
`mysql_upgrade`
ที่โฟลเดอร์
`xampp/bin`
-
รันไฟล์ชื่อ
`mysql_upgrade`
ที่โฟลเดอร์
`xampp/bin`
-
กำหนดสิทธิ์ admin
-
หลังจากสมัครสมาชิก เข้าไปยังฐานข้อมูลและเปลี่ยน
`rank`
ของ user เป็น 1
-
เมื่อเปลี่ยนเสร็จ ต้องทำการเข้าสู่ระบบใหม่อีกครั้ง
...
...
app/controllers/AdminOrderController.js
View file @
f147ee7d
...
...
@@ -15,6 +15,26 @@ const AdminOrderController = {
res
.
status
(
403
).
json
({
status
:
403
,
message
:
"error something"
});
}
},
/**
*
* @param {Request} req
* @param {Response} res
*/
async
sending
(
req
,
res
)
{
try
{
const
{
id
,
sending
}
=
req
.
body
;
if
(
!
id
)
throw
300
;
await
db
.
order
.
update
({
where
:
{
id
:
Number
(
id
)
},
data
:
{
send_status
:
Number
(
sending
)
},
});
await
db
.
$disconnect
();
res
.
json
({
status
:
301
,
message
:
"update sending success"
});
}
catch
(
err
)
{
console
.
log
(
err
);
res
.
json
({
status
:
300
,
message
:
"Error with server"
});
}
},
};
export
default
AdminOrderController
;
app/routes/admin.js
View file @
f147ee7d
...
...
@@ -18,5 +18,6 @@ adminRouter.put("/category", CategoryController.update);
adminRouter
.
delete
(
"/category"
,
CategoryController
.
delete
);
adminRouter
.
get
(
"/order"
,
AdminOrderController
.
index
);
adminRouter
.
put
(
"/order/sending"
,
AdminOrderController
.
sending
);
export
default
adminRouter
;
src/pages/admin/order.js
View file @
f147ee7d
...
...
@@ -14,17 +14,41 @@ import {
TableRow
,
TableCell
,
TableBody
,
FormControl
,
Select
,
MenuItem
,
}
from
"@mui/material"
;
export
default
function
Order
()
{
const
user
=
useContext
(
UserContext
);
const
adminOrder
=
useContext
(
AdminOrderContext
);
const
[
message
,
setMessage
]
=
useState
({
message
:
""
,
error
:
false
});
useEffect
(()
=>
{
console
.
log
(
adminOrder
.
value
);
},
[
user
]);
const
onSendingChange
=
async
(
id
,
sending
)
=>
{
try
{
let
response
=
await
axios
.
put
(
"/api/admin/order/sending"
,
{
id
,
sending
},
{
headers
:
{
token
:
user
.
value
?.
token
}
}
);
if
(
response
.
data
.
status
===
301
)
{
setMessage
({
message
:
"อัพเดทสถานะการจัดส่งสำเร็จ"
,
error
:
false
});
setTimeout
(()
=>
{
setMessage
({
message
:
""
,
error
:
false
});
},
2000
);
adminOrder
.
fetch
();
}
}
catch
(
err
)
{
console
.
error
(
err
);
setMessage
({
message
:
"เกิดข้อผิดพลาด กรุณาลองใหม่อีกครั้ง"
,
error
:
true
,
});
setTimeout
(()
=>
{
setMessage
({
message
:
""
,
error
:
true
});
},
2000
);
}
};
return
(
<>
...
...
@@ -76,17 +100,33 @@ export default function Order() {
<
TableCell
>
{
order
.
shipping_price
}
<
/TableCell
>
<
TableCell
>
<
Box
color
=
{
order
.
pay_status
?
"green"
:
"red"
}
>
{
order
.
pay_status
?
(
"ชำระเงินแล้ว"
)
:
(
"ยังไม่ชำระเงิน"
)}
{
order
.
pay_status
?
"ชำระเงินแล้ว"
:
"ยังไม่ชำระเงิน"
}
<
/Box
>
<
/TableCell
>
<
TableCell
>
<
Box
color
=
{
order
.
send_status
?
"green"
:
"red"
}
>
{
order
.
send_status
?
"ส่งแล้ว"
:
"ยังไม่จัดส่ง"
}
<
/Box
>
<
FormControl
variant
=
"standard"
>
<
Select
value
=
{
Number
(
order
.
send_status
)}
onChange
=
{(
e
)
=>
{
onSendingChange
(
Number
(
order
.
id
),
Number
(
e
.
target
.
value
)
);
}}
>
<
MenuItem
value
=
{
0
}
>
<
Box
color
=
"red"
>
ยังไม่จัดส่ง
<
/Box
>
<
/MenuItem
>
<
MenuItem
value
=
{
1
}
>
<
Box
color
=
"orangered"
>
กำลังจัดส่ง
<
/Box
>
<
/MenuItem
>
<
MenuItem
value
=
{
2
}
>
<
Box
color
=
"green"
>
จัดส่งแล้ว
<
/Box
>
<
/MenuItem
>
<
/Select
>
<
/FormControl
>
<
/TableCell
>
<
/TableRow
>
)
...
...
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