@tmlmobilidade/interfaces 20251029.1408.3 → 20251031.1036.20
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.
|
@@ -6,13 +6,15 @@ declare class AuthProvider {
|
|
|
6
6
|
*/
|
|
7
7
|
static getInstance(): Promise<AuthProvider>;
|
|
8
8
|
/**
|
|
9
|
-
* Get Permissions for a user based on their session token.
|
|
10
|
-
* @param
|
|
11
|
-
* @param scope - The scope to check
|
|
12
|
-
* @param action - The action to check
|
|
9
|
+
* Get Permissions for a user based on their session token or user_id.
|
|
10
|
+
* @param params - Object containing either sessionToken or user_id
|
|
13
11
|
* @returns The permissions that the user has
|
|
14
12
|
*/
|
|
15
|
-
getPermissions<T>(
|
|
13
|
+
getPermissions<T>(params: {
|
|
14
|
+
sessionToken: string;
|
|
15
|
+
} | {
|
|
16
|
+
user_id: string;
|
|
17
|
+
}): Promise<Permission<T>[]>;
|
|
16
18
|
/**
|
|
17
19
|
* Gets a user by their session token.
|
|
18
20
|
* @param sessionToken The session token to look up.
|
|
@@ -17,17 +17,28 @@ class AuthProvider {
|
|
|
17
17
|
return AuthProvider._instance;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
20
|
-
* Get Permissions for a user based on their session token.
|
|
21
|
-
* @param
|
|
22
|
-
* @param scope - The scope to check
|
|
23
|
-
* @param action - The action to check
|
|
20
|
+
* Get Permissions for a user based on their session token or user_id.
|
|
21
|
+
* @param params - Object containing either sessionToken or user_id
|
|
24
22
|
* @returns The permissions that the user has
|
|
25
23
|
*/
|
|
26
|
-
async getPermissions(
|
|
24
|
+
async getPermissions(params) {
|
|
27
25
|
//
|
|
28
26
|
//
|
|
29
27
|
// Get the user and their roles
|
|
30
|
-
|
|
28
|
+
let userData;
|
|
29
|
+
if ('user_id' in params) {
|
|
30
|
+
const foundUser = await users.findOne({ _id: { $eq: params.user_id } });
|
|
31
|
+
if (!foundUser) {
|
|
32
|
+
throw new HttpException(HttpStatus.UNAUTHORIZED, 'User not found');
|
|
33
|
+
}
|
|
34
|
+
userData = foundUser;
|
|
35
|
+
}
|
|
36
|
+
else if ('sessionToken' in params) {
|
|
37
|
+
userData = await this.getUser(params.sessionToken);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
throw new HttpException(HttpStatus.BAD_REQUEST, 'Either sessionToken or user_id must be provided');
|
|
41
|
+
}
|
|
31
42
|
const rolesData = await roles.findMany({ _id: { $in: userData.role_ids } });
|
|
32
43
|
const allPermissions = [...rolesData.flatMap(role => role.permissions), ...userData.permissions];
|
|
33
44
|
const permissionsMap = new Map();
|
package/package.json
CHANGED