@felloh-org/lambda-wrapper 1.1.46 → 1.1.47

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.
@@ -63,6 +63,20 @@ class AuthenticationService extends _dependencyAware.default {
63
63
 
64
64
  return response;
65
65
  }
66
+ /**
67
+ * Fetch roles for a user
68
+ * @param userID
69
+ * @returns {Promise<any[]>}
70
+ */
71
+
72
+
73
+ async fetchUserRoles(userID) {
74
+ await this.initialise();
75
+ const roles = await this.userRoleRepository.createQueryBuilder('user_roles').leftJoinAndSelect('user_roles.role', 'role').where('user_id = :userID', {
76
+ userID
77
+ }).getMany();
78
+ return roles.map(role => role.role.machine_name);
79
+ }
66
80
  /**
67
81
  * Check user role and organisation access
68
82
  * @param organisationID
@@ -103,14 +117,12 @@ class AuthenticationService extends _dependencyAware.default {
103
117
 
104
118
  if (roles.length >= 1) {
105
119
  // Fetch the users assigned roles
106
- const userRoles = await this.userRoleRepository.createQueryBuilder('user_roles').leftJoinAndSelect('user_roles.role', 'role').where('user_id = :userID', {
107
- userID: this.user.id
108
- }).getMany(); // Loop through the roles and determine match count
120
+ const userRoles = await this.fetchUserRoles(this.user.id); // Loop through the roles and determine match count
109
121
 
110
122
  let roleCount = 0;
111
123
 
112
124
  for (const userRole of userRoles) {
113
- if (roles.indexOf(userRole.role.machine_name) !== -1) {
125
+ if (roles.indexOf(userRole) !== -1) {
114
126
  roleCount += 1;
115
127
  }
116
128
  } // Throw an error if the user does not have all the roles
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@felloh-org/lambda-wrapper",
3
- "version": "1.1.46",
3
+ "version": "1.1.47",
4
4
  "description": "Lambda wrapper for all Felloh Serverless Projects",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {