rez_core 2.1.26 → 2.1.27

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": "rez_core",
3
- "version": "2.1.26",
3
+ "version": "2.1.27",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "private": false,
@@ -28,7 +28,7 @@ export class LoginService {
28
28
 
29
29
  async login(email: string, password: string) {
30
30
  const user = await this.userService.findByEmailId(email);
31
-
31
+
32
32
  if (!user) {
33
33
  return {
34
34
  success: false,
@@ -36,7 +36,7 @@ export class LoginService {
36
36
  type: 'email',
37
37
  };
38
38
  }
39
-
39
+
40
40
  if (user.status !== 'ACTIVE') {
41
41
  return {
42
42
  success: false,
@@ -44,13 +44,13 @@ export class LoginService {
44
44
  type: 'email',
45
45
  };
46
46
  }
47
-
47
+
48
48
  const encryptedPassword = EncryptUtilService.encryptGCM(
49
49
  password,
50
50
  this.masterKey,
51
51
  this.masterIv,
52
52
  );
53
-
53
+
54
54
  if (encryptedPassword !== user.password) {
55
55
  return {
56
56
  success: false,
@@ -58,64 +58,67 @@ export class LoginService {
58
58
  type: 'password',
59
59
  };
60
60
  }
61
-
61
+
62
62
  let defaultAccess;
63
-
64
- if (!user.last_level_type && !user.last_level_id) {
65
- const roleMappings = await this.userRoleMappingRepository.find({
66
- where: {
67
- user_id: user.id,
68
- appcode: user.last_app_access,
69
- },
70
- });
71
-
72
- if (!roleMappings.length) {
73
- throw new BadRequestException(
74
- 'User does not have any access mapped for this app.',
75
- );
76
- }
77
-
78
- // ✅ Pick default access based on priority
79
- const priority = { org: 1, sch: 2, brn: 3 };
80
- defaultAccess = roleMappings.sort(
81
- (a, b) => priority[a.level_type] - priority[b.level_type],
82
- )[0];
83
-
84
- if ((defaultAccess.level_type, defaultAccess.level_id)) {
85
- await this.userService.setLastLevelTypeAndId(
86
- user.id,
87
- defaultAccess.level_type,
88
- defaultAccess.level_id,
89
- );
90
- }
91
- } else {
92
- defaultAccess = {
93
- level_type: user.last_level_type,
94
- level_id: user.last_level_id,
95
- };
96
- }
97
-
98
- //appcode
99
-
100
63
  let appcode = user.last_app_access;
101
-
64
+
102
65
  if (!appcode) {
103
66
  appcode = 'ADM';
104
67
  await this.userService.setDefaultLastAccess(user.id, appcode);
105
68
  }
106
-
69
+
70
+ // ✅ Always fetch role mappings for the user + app
71
+ const roleMappings = await this.userRoleMappingRepository.find({
72
+ where: {
73
+ user_id: user.id,
74
+ appcode,
75
+ },
76
+ });
77
+
78
+ if (!roleMappings.length) {
79
+ throw new BadRequestException(
80
+ 'User does not have any access mapped for this app.',
81
+ );
82
+ }
83
+
84
+ // 🔍 If user.last_level_type & level_id exist, validate them against URM
85
+ const validURM = roleMappings.find(
86
+ (r) =>
87
+ r.level_type === user.last_level_type &&
88
+ r.level_id === user.last_level_id,
89
+ );
90
+
91
+ if (user.last_level_type && user.last_level_id && validURM) {
92
+ defaultAccess = {
93
+ level_type: user.last_level_type,
94
+ level_id: user.last_level_id,
95
+ };
96
+ } else {
97
+ // ❌ Fallback: Pick default based on priority
98
+ const priority = { org: 1, sch: 2, brn: 3 };
99
+ defaultAccess = roleMappings.sort(
100
+ (a, b) => priority[a.level_type] - priority[b.level_type],
101
+ )[0];
102
+
103
+ await this.userService.setLastLevelTypeAndId(
104
+ user.id,
105
+ defaultAccess.level_type,
106
+ defaultAccess.level_id,
107
+ );
108
+ }
109
+
107
110
  const token = await this.userSessionService.createSession(user, appcode, {
108
111
  level_type: defaultAccess.level_type,
109
112
  level_id: defaultAccess.level_id,
110
113
  });
111
-
114
+
112
115
  if (user.is_firstlogin === 1) {
113
116
  user.invitation_status = 'ACCEPTED';
114
117
  user.is_firstlogin = 0;
115
118
  const { password, ...userWithoutPassword } = user;
116
119
  await this.userService.updateEntity(userWithoutPassword, user);
117
120
  }
118
-
121
+
119
122
  return {
120
123
  success: true,
121
124
  accessToken: token,
@@ -124,6 +127,7 @@ export class LoginService {
124
127
  level_id: defaultAccess.level_id,
125
128
  };
126
129
  }
130
+
127
131
 
128
132
  async loginWithGoogle(email: string, name) {
129
133
  let user = await this.userService.findByEmailId(email);