Skip to content

Commit ce0dbe1

Browse files
add support to other roles update in staging (#1354)
* add support to other roles * modify condition to forbid in production
1 parent 39bc7c0 commit ce0dbe1

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

controllers/staging.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,21 @@ const { addOrUpdate } = require("../models/users");
33
const updateRoles = async (req, res) => {
44
try {
55
const userData = await req.userData;
6-
if (process.env.NODE_ENV !== "production") {
6+
if (process.env.NODE_ENV === "production") {
77
return res.status(403).json({
88
message: "FORBIDDEN | To be used only in staging and development",
99
});
1010
}
1111
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,
1917
},
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+
);
3321
return res.status(200).json({
3422
message: "Roles Updated successfully",
3523
});

middlewares/validators/staging.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
const joi = require("joi");
22

33
const validateUserRoles = async (req, res, next) => {
4-
const config = {
4+
const schema = joi.object().strict().keys({
55
super_user: joi.boolean().optional(),
66
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+
});
910

1011
try {
1112
await schema.validateAsync(req.body);

0 commit comments

Comments
 (0)