soul-cli 0.7.5 → 0.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soul-cli",
3
- "version": "0.7.5",
3
+ "version": "0.7.6",
4
4
  "description": "A SQLite REST and Realtime server",
5
5
  "main": "src/server.js",
6
6
  "bin": {
@@ -59,12 +59,18 @@ const obtainAccessToken = async (req, res) => {
59
59
 
60
60
  // if the user is not a superuser get the role and its permission from the DB
61
61
  if (!toBoolean(user.is_superuser)) {
62
- const roleData = getUsersRoleAndPermission({
63
- userId: user.id,
64
- res,
65
- });
66
-
67
- roleIds = roleData.roleIds;
62
+ try {
63
+ const roleData = getUsersRoleAndPermission({
64
+ userId: user.id,
65
+ res,
66
+ });
67
+
68
+ roleIds = roleData.roleIds;
69
+ } catch (err) {
70
+ return res
71
+ .status(401)
72
+ .send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
73
+ }
68
74
  }
69
75
 
70
76
  const payload = {
@@ -162,12 +168,17 @@ const refreshAccessToken = async (req, res) => {
162
168
 
163
169
  // if the user is not a superuser get the role and its permission from the DB
164
170
  if (!toBoolean(user.is_superuser)) {
165
- const roleData = getUsersRoleAndPermission({
166
- userId: user.id,
167
- res,
168
- });
169
-
170
- roleIds = roleData.roleIds;
171
+ try {
172
+ const roleData = getUsersRoleAndPermission({
173
+ userId: user.id,
174
+ });
175
+
176
+ roleIds = roleData.roleIds;
177
+ } catch (err) {
178
+ return res
179
+ .status(401)
180
+ .send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
181
+ }
171
182
  }
172
183
 
173
184
  const newPayload = {
@@ -271,11 +282,10 @@ const removeRevokedRefreshTokens = () => {
271
282
  });
272
283
  };
273
284
 
274
- const getUsersRoleAndPermission = ({ userId, res }) => {
285
+ const getUsersRoleAndPermission = ({ userId }) => {
275
286
  const userRoles = authService.getUserRoleByUserId({ userId });
276
287
 
277
- if (userRoles <= 0) {
278
- res.status(401).send({ message: errorMessage.ROLE_NOT_FOUND_ERROR });
288
+ if (userRoles.length <= 0) {
279
289
  throw new Error(errorMessage.ROLE_NOT_FOUND_ERROR);
280
290
  }
281
291