rez_core 2.0.47 → 2.0.49

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.
Files changed (34) hide show
  1. package/dist/module/auth/strategies/jwt.strategy.js +1 -1
  2. package/dist/module/auth/strategies/jwt.strategy.js.map +1 -1
  3. package/dist/module/user/controller/login.controller.d.ts +10 -1
  4. package/dist/module/user/controller/login.controller.js +21 -2
  5. package/dist/module/user/controller/login.controller.js.map +1 -1
  6. package/dist/module/user/dto/create-user.dto.d.ts +1 -0
  7. package/dist/module/user/dto/create-user.dto.js.map +1 -1
  8. package/dist/module/user/repository/role.repository.d.ts +6 -0
  9. package/dist/module/user/repository/role.repository.js +27 -0
  10. package/dist/module/user/repository/role.repository.js.map +1 -1
  11. package/dist/module/user/repository/user-role-mapping.repository.d.ts +5 -1
  12. package/dist/module/user/repository/user-role-mapping.repository.js +37 -2
  13. package/dist/module/user/repository/user-role-mapping.repository.js.map +1 -1
  14. package/dist/module/user/service/role.service.js +8 -5
  15. package/dist/module/user/service/role.service.js.map +1 -1
  16. package/dist/module/user/service/user-role-mapping.service.d.ts +3 -0
  17. package/dist/module/user/service/user-role-mapping.service.js +24 -1
  18. package/dist/module/user/service/user-role-mapping.service.js.map +1 -1
  19. package/dist/module/user/service/user-session.service.d.ts +10 -1
  20. package/dist/module/user/service/user-session.service.js +24 -2
  21. package/dist/module/user/service/user-session.service.js.map +1 -1
  22. package/dist/module/user/service/user.service.js +57 -23
  23. package/dist/module/user/service/user.service.js.map +1 -1
  24. package/dist/tsconfig.build.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/src/module/auth/strategies/jwt.strategy.ts +2 -2
  27. package/src/module/user/controller/login.controller.ts +32 -1
  28. package/src/module/user/dto/create-user.dto.ts +2 -0
  29. package/src/module/user/repository/role.repository.ts +46 -2
  30. package/src/module/user/repository/user-role-mapping.repository.ts +54 -1
  31. package/src/module/user/service/role.service.ts +10 -6
  32. package/src/module/user/service/user-role-mapping.service.ts +60 -0
  33. package/src/module/user/service/user-session.service.ts +140 -11
  34. package/src/module/user/service/user.service.ts +75 -65
@@ -42,9 +42,7 @@ export class UserService extends EntityServiceImpl {
42
42
  manager?: EntityManager,
43
43
  ): Promise<BaseEntity> {
44
44
  let userData = entityData as CreateUserDto;
45
- // if (appcode) {
46
- // userData.appcode = appcode;
47
- // }
45
+
48
46
  let existingUser = await this.userRepository.findByEmailId(
49
47
  userData.email_id,
50
48
  loggedInUser?.organization_id,
@@ -83,62 +81,43 @@ export class UserService extends EntityServiceImpl {
83
81
  userData.invitation_status = 'SENT';
84
82
  userData.status = STATUS_ACTIVE;
85
83
  const savedData = await super.createEntity(userData, loggedInUser);
86
- userData.roles.push('1');
87
- userData.roles.push('2');
88
- if (userData.roles) {
89
- let roles = userData.roles;
90
- await this.userRoleMappingService.deleteByUserId(userData.id);
91
- for (const role in roles) {
92
- let userRoleMapping = new UserRoleMapping(
93
- savedData.id,
94
- Number(roles[role]),
95
- );
96
84
 
97
- await this.userRoleMappingService.assignUserRole(userRoleMapping);
98
- }
99
- }
85
+ const insertPromises: any = [];
100
86
 
101
- //Assign user app mapping as per user
87
+ for (const entry of userData.access || []) {
88
+ const { level_type, level_ids, app_code, role_id } = entry;
102
89
 
103
- const appcodedata = ['CRM', 'ERP'];
90
+ if (
91
+ !level_type ||
92
+ !Array.isArray(level_ids) ||
93
+ !level_ids.length ||
94
+ !app_code ||
95
+ !role_id
96
+ ) {
97
+ throw new BadRequestException('Invalid access level entry');
98
+ }
104
99
 
105
- if (savedData.id) {
106
- for (const app of appcodedata) {
107
- await this.userAppMappingService.assignUserAppMapping(
108
- savedData.id,
109
- app,
100
+ for (const levelId of level_ids) {
101
+ const userRoleMapping = new UserRoleMapping(savedData.id, role_id);
102
+ userRoleMapping.level_type = level_type;
103
+ userRoleMapping.level_id = String(levelId);
104
+ userRoleMapping.appcode = app_code;
105
+ userRoleMapping.organization_id = loggedInUser?.organization_id || 0;
106
+ insertPromises.push(
107
+ this.userRoleMappingService.assignUserRole(userRoleMapping),
110
108
  );
111
109
  }
112
110
  }
113
111
 
114
- // let role = new Role();
115
- // role.organization_id = savedData.organization_id;
116
- // role.enterprise_id = savedData.enterprise_id;
117
- // role.is_system = 1;
118
- // role.status = 'ACTIVE';
119
- // role.name = 'School Admin';
120
-
121
- // let defaultadminERP: string | undefined = 'ADMIN';
122
- // let defaultadminCRM: string | undefined = 'ADMIN_CRM';
123
-
124
- // if (defaultadminERP && defaultadminCRM) {
125
- // let defaultAdminRoleERP = await this.roleService.findByCode(
126
- // ENTITYTYPE_ROLE,
127
- // defaultadminERP,
128
- // );
129
- // let defaultAdminRoleCRM = await this.roleService.findByCode(
130
- // ENTITYTYPE_ROLE,
131
- // defaultadminCRM,
132
- // );
133
- // if (defaultAdminRoleERP) {
134
- // role.copy_from_role_id = defaultAdminRoleERP.id;
135
- // let savedRoleERP = await this.roleService.createEntity(role, null);
136
- // }
137
- // if (defaultAdminRoleCRM) {
138
- // role.copy_from_role_id = defaultAdminRoleCRM.id;
139
- // let savedRoleCRM = await this.roleService.createEntity(role, null);
140
- // }
141
- // }
112
+ try {
113
+ if (insertPromises.length > 0) {
114
+ await Promise.all(insertPromises);
115
+ }
116
+ console.log('Access levels added successfully');
117
+ } catch (error) {
118
+ console.error('Error adding access levels:', error);
119
+ throw new BadRequestException('Failed to add access levels');
120
+ }
142
121
 
143
122
  return savedData;
144
123
  }
@@ -173,14 +152,11 @@ export class UserService extends EntityServiceImpl {
173
152
  ): Promise<BaseEntity> {
174
153
  const userDto = entityData as UpdateUserDto;
175
154
 
176
- // Fetch the current user data from DB to get the existing encrypted password
177
155
  const existingUser = await this.userRepository.findById(entityData.id);
178
-
179
156
  if (!existingUser) {
180
157
  throw new BadRequestException('User not found');
181
158
  }
182
159
 
183
- // If password is being updated, check if it's the same as existing one
184
160
  if (userDto.password) {
185
161
  const decryptedPassword = EncryptUtilService.decryptGCM(
186
162
  existingUser.password,
@@ -194,25 +170,59 @@ export class UserService extends EntityServiceImpl {
194
170
  );
195
171
  }
196
172
 
197
- // Encrypt new password
198
- const encryptedPassword = EncryptUtilService.encryptGCM(
173
+ userDto.password = EncryptUtilService.encryptGCM(
199
174
  userDto.password,
200
175
  this.masterKey,
201
176
  this.masterIv,
202
177
  );
203
- userDto.password = encryptedPassword;
204
178
  }
205
179
 
206
- const userData = plainToInstance(UserData, userDto);
180
+ const updatedUserData = { ...userDto } as any;
181
+ delete updatedUserData.access;
182
+
183
+ const savedData = await super.updateEntity(
184
+ updatedUserData,
185
+ loggedInUserData,
186
+ );
207
187
 
208
- const savedData = await super.updateEntity(userData, loggedInUserData);
188
+ // Handle updated access levels
189
+ if (userDto.access && userDto.access.length > 0) {
190
+ const insertPromises: any[] = [];
191
+
192
+ for (const entry of userDto.access) {
193
+ const { id, level_type, level_ids, app_code, role_id } = entry;
194
+
195
+ if (
196
+ !level_type ||
197
+ typeof level_ids !== 'number' ||
198
+ !app_code ||
199
+ !role_id
200
+ ) {
201
+ throw new BadRequestException('Invalid access level entry');
202
+ }
203
+
204
+ const userRoleMapping = new UserRoleMapping(savedData.id, role_id);
205
+ if (id) {
206
+ userRoleMapping.id = id; // Use the existing ID if provided
207
+ }
208
+
209
+ userRoleMapping.role_id = role_id;
210
+ userRoleMapping.appcode = app_code;
211
+ userRoleMapping.level_id = String(level_ids); // level_ids is now a number
212
+ userRoleMapping.level_type = level_type;
213
+ userRoleMapping.organization_id = loggedInUserData.organization_id || 0;
214
+
215
+ insertPromises.push(
216
+ this.userRoleMappingService.updateAssignedRole(userRoleMapping),
217
+ );
218
+ }
209
219
 
210
- // Update roles if provided
211
- if (userDto.roles) {
212
- await this.userRoleMappingService.deleteByUserId(savedData.id); // prevent duplicates
213
- for (const role of userDto.roles) {
214
- const userRoleMapping = new UserRoleMapping(savedData.id, Number(role));
215
- await this.userRoleMappingService.assignUserRole(userRoleMapping);
220
+ try {
221
+ await Promise.all(insertPromises);
222
+ console.log('Access levels updated successfully');
223
+ } catch (error) {
224
+ console.error('Error updating access levels:', error);
225
+ throw new BadRequestException('Failed to update access levels');
216
226
  }
217
227
  }
218
228