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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
12 deletions
+73
-12
README.md
README.md
+0
-0
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
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