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.
- package/dist/module/auth/strategies/jwt.strategy.js +1 -1
- package/dist/module/auth/strategies/jwt.strategy.js.map +1 -1
- package/dist/module/user/controller/login.controller.d.ts +10 -1
- package/dist/module/user/controller/login.controller.js +21 -2
- package/dist/module/user/controller/login.controller.js.map +1 -1
- package/dist/module/user/dto/create-user.dto.d.ts +1 -0
- package/dist/module/user/dto/create-user.dto.js.map +1 -1
- package/dist/module/user/repository/role.repository.d.ts +6 -0
- package/dist/module/user/repository/role.repository.js +27 -0
- package/dist/module/user/repository/role.repository.js.map +1 -1
- package/dist/module/user/repository/user-role-mapping.repository.d.ts +5 -1
- package/dist/module/user/repository/user-role-mapping.repository.js +37 -2
- package/dist/module/user/repository/user-role-mapping.repository.js.map +1 -1
- package/dist/module/user/service/role.service.js +8 -5
- package/dist/module/user/service/role.service.js.map +1 -1
- package/dist/module/user/service/user-role-mapping.service.d.ts +3 -0
- package/dist/module/user/service/user-role-mapping.service.js +24 -1
- package/dist/module/user/service/user-role-mapping.service.js.map +1 -1
- package/dist/module/user/service/user-session.service.d.ts +10 -1
- package/dist/module/user/service/user-session.service.js +24 -2
- package/dist/module/user/service/user-session.service.js.map +1 -1
- package/dist/module/user/service/user.service.js +57 -23
- package/dist/module/user/service/user.service.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/module/auth/strategies/jwt.strategy.ts +2 -2
- package/src/module/user/controller/login.controller.ts +32 -1
- package/src/module/user/dto/create-user.dto.ts +2 -0
- package/src/module/user/repository/role.repository.ts +46 -2
- package/src/module/user/repository/user-role-mapping.repository.ts +54 -1
- package/src/module/user/service/role.service.ts +10 -6
- package/src/module/user/service/user-role-mapping.service.ts +60 -0
- package/src/module/user/service/user-session.service.ts +140 -11
- 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
|
-
|
|
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
|
-
|
|
98
|
-
}
|
|
99
|
-
}
|
|
85
|
+
const insertPromises: any = [];
|
|
100
86
|
|
|
101
|
-
|
|
87
|
+
for (const entry of userData.access || []) {
|
|
88
|
+
const { level_type, level_ids, app_code, role_id } = entry;
|
|
102
89
|
|
|
103
|
-
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
|