rez_core 1.0.54 → 1.0.56
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
|
@@ -175,18 +175,33 @@ export class ModuleAccessRepository {
|
|
|
175
175
|
if (nameExists) {
|
|
176
176
|
throw new BadRequestException('Role name already exists.');
|
|
177
177
|
}
|
|
178
|
+
if(copyFromRoleId){
|
|
179
|
+
const sourceRole = await this.roleRepo.findOne({
|
|
180
|
+
where: { id: copyFromRoleId },
|
|
181
|
+
});
|
|
182
|
+
if (!sourceRole) {
|
|
183
|
+
throw new BadRequestException('Source role not found');
|
|
184
|
+
}
|
|
185
|
+
}
|
|
178
186
|
|
|
179
|
-
|
|
187
|
+
// 1. Create the role without the code (code will be updated after ID is generated)
|
|
180
188
|
const newRole = this.roleRepo.create({
|
|
181
189
|
name,
|
|
182
|
-
code,
|
|
183
190
|
description,
|
|
184
191
|
status: status || 'ACTIVE',
|
|
185
192
|
created_by: loggedInUser.id,
|
|
186
193
|
created_date: new Date(),
|
|
187
194
|
});
|
|
188
195
|
|
|
189
|
-
|
|
196
|
+
// 2. Save the role to get the generated ID
|
|
197
|
+
const savedRole = await this.roleRepo.save(newRole); // ID is now available
|
|
198
|
+
|
|
199
|
+
// 3. Generate the code using the saved ID
|
|
200
|
+
const generatedCode = `ROL${savedRole.id}`;
|
|
201
|
+
|
|
202
|
+
// 4. Update the role with the generated code
|
|
203
|
+
savedRole.code = generatedCode;
|
|
204
|
+
await this.roleRepo.save(savedRole); // Update only the code
|
|
190
205
|
|
|
191
206
|
if (copyFromRoleId) {
|
|
192
207
|
const sourceRole = await this.roleRepo.findOne({
|
|
@@ -200,7 +215,7 @@ export class ModuleAccessRepository {
|
|
|
200
215
|
});
|
|
201
216
|
const clonedPermissions = sourcePermissions.map((perm) =>
|
|
202
217
|
this.moduleAccessRepo.create({
|
|
203
|
-
role_code:
|
|
218
|
+
role_code: generatedCode,
|
|
204
219
|
module_code: perm.module_code,
|
|
205
220
|
action_type: perm.action_type,
|
|
206
221
|
access_flag: perm.access_flag,
|
|
@@ -303,4 +318,4 @@ export class ModuleAccessRepository {
|
|
|
303
318
|
const existingRole = await query.getOne();
|
|
304
319
|
return !!existingRole;
|
|
305
320
|
}
|
|
306
|
-
}
|
|
321
|
+
}
|