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
587d26bd
Commit
587d26bd
authored
Oct 02, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change rank of user by admin
parent
452287af
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
2 deletions
+30
-2
AdminUserController.js
app/controllers/AdminUserController.js
+20
-0
admin.js
app/routes/admin.js
+1
-0
member.js
src/pages/admin/member.js
+9
-2
No files found.
app/controllers/AdminUserController.js
View file @
587d26bd
...
...
@@ -11,6 +11,25 @@ const AdminUserController = {
db
.
$disconnect
();
res
.
json
(
userAll
);
},
/**
*
* @param {Request} req
* @param {Response} res
*/
async
chageRank
(
req
,
res
)
{
try
{
const
{
id
,
rank
}
=
req
.
body
;
if
(
!
id
)
throw
300
;
await
db
.
user
.
update
({
where
:
{
id
:
Number
(
id
)
},
data
:
{
rank
:
!!
rank
},
});
await
db
.
$disconnect
();
res
.
json
({
status
:
301
,
message
:
"update rank success"
});
}
catch
(
err
)
{
res
.
json
({
status
:
300
,
message
:
"change error on server"
});
}
},
/**
*
* @param {Request} req
...
...
@@ -21,6 +40,7 @@ const AdminUserController = {
const
{
id
}
=
req
.
query
;
if
(
!
id
)
throw
400
;
await
db
.
user
.
delete
({
where
:
{
id
:
Number
(
id
)
}
});
await
db
.
$disconnect
();
res
.
json
({
status
:
401
,
message
:
"delete success"
,
...
...
app/routes/admin.js
View file @
587d26bd
...
...
@@ -6,6 +6,7 @@ const adminRouter = express.Router();
adminRouter
.
get
(
"/user"
,
AdminUserController
.
index
);
adminRouter
.
delete
(
"/user"
,
AdminUserController
.
delete
);
adminRouter
.
put
(
"/user/rank"
,
AdminUserController
.
chageRank
);
adminRouter
.
post
(
"/product"
,
AdminProductController
.
create
);
adminRouter
.
put
(
"/product"
,
AdminProductController
.
update
);
...
...
src/pages/admin/member.js
View file @
587d26bd
...
...
@@ -19,12 +19,19 @@ export default function Member() {
const
[
userAll
,
setUserAll
]
=
useState
([]);
const
[
deleteState
,
setDeleteState
]
=
useState
({
open
:
false
,
id
:
-
1
});
async
function
changeRank
(
id
,
rank
)
{
let
response
=
await
axios
.
put
(
"/api/admin/user/rank"
,
{
id
,
rank
},
{
headers
:
{
token
:
user
.
value
.
token
}
}
);
fetchApi
();
}
async
function
fetchApi
()
{
try
{
let
response
=
await
axios
.
get
(
"/api/admin/user"
,
{
headers
:
{
token
:
user
.
value
.
token
},
});
console
.
log
(
response
.
data
);
setUserAll
(
response
.
data
);
}
catch
(
err
)
{}
}
...
...
@@ -74,7 +81,7 @@ export default function Member() {
<
TableCell
sx
=
{{
textAlign
:
"center"
}}
>
<
Switch
checked
=
{
!!
user
.
rank
}
onChange
=
{()
=>
alert
(
"change rank"
)}
onChange
=
{()
=>
changeRank
(
user
.
id
,
!
user
.
rank
)}
/
>
<
/TableCell
>
<
TableCell
sx
=
{{
textAlign
:
"center"
}}
>
...
...
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