File tree Expand file tree Collapse file tree 2 files changed +13
-24
lines changed Expand file tree Collapse file tree 2 files changed +13
-24
lines changed Original file line number Diff line number Diff line change @@ -3,33 +3,21 @@ const { addOrUpdate } = require("../models/users");
3
3
const updateRoles = async ( req , res ) => {
4
4
try {
5
5
const userData = await req . userData ;
6
- if ( process . env . NODE_ENV ! == "production" ) {
6
+ if ( process . env . NODE_ENV = == "production" ) {
7
7
return res . status ( 403 ) . json ( {
8
8
message : "FORBIDDEN | To be used only in staging and development" ,
9
9
} ) ;
10
10
}
11
11
const userId = req . userData . id ;
12
- if ( req . body . super_user ) {
13
- await addOrUpdate (
14
- {
15
- roles : {
16
- ...userData . roles ,
17
- super_user : req . body . super_user ,
18
- } ,
12
+ await addOrUpdate (
13
+ {
14
+ roles : {
15
+ ...userData . roles ,
16
+ ...req . body ,
19
17
} ,
20
- userId
21
- ) ;
22
- } else if ( req . body . member ) {
23
- await addOrUpdate (
24
- {
25
- roles : {
26
- ...userData . roles ,
27
- member : req . body . member ,
28
- } ,
29
- } ,
30
- userId
31
- ) ;
32
- }
18
+ } ,
19
+ userId
20
+ ) ;
33
21
return res . status ( 200 ) . json ( {
34
22
message : "Roles Updated successfully" ,
35
23
} ) ;
Original file line number Diff line number Diff line change 1
1
const joi = require ( "joi" ) ;
2
2
3
3
const validateUserRoles = async ( req , res , next ) => {
4
- const config = {
4
+ const schema = joi . object ( ) . strict ( ) . keys ( {
5
5
super_user : joi . boolean ( ) . optional ( ) ,
6
6
member : joi . boolean ( ) . optional ( ) ,
7
- } ;
8
- const schema = joi . object ( config ) . xor ( "super_user" , "member" ) ;
7
+ archive : joi . boolean ( ) . optional ( ) ,
8
+ in_discord : joi . boolean ( ) . optional ( ) ,
9
+ } ) ;
9
10
10
11
try {
11
12
await schema . validateAsync ( req . body ) ;
You can’t perform that action at this time.
0 commit comments