@tomei/sso 0.34.1 → 0.34.2

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/sso",
3
- "version": "0.34.1",
3
+ "version": "0.34.2",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,4 +8,19 @@ export class GroupRepository
8
8
  constructor() {
9
9
  super(GroupModel);
10
10
  }
11
+ v;
12
+
13
+ async delete(GroupCode: string, dbTransaction?: any) {
14
+ try {
15
+ const options = {
16
+ where: {
17
+ GroupCode: GroupCode,
18
+ },
19
+ transaction: dbTransaction,
20
+ };
21
+ await GroupModel.destroy(options);
22
+ } catch (error) {
23
+ throw new Error(`An Error occured when delete : ${error.message}`);
24
+ }
25
+ }
11
26
  }
@@ -460,6 +460,92 @@ export class Group extends ObjectBase {
460
460
  }
461
461
  }
462
462
 
463
+ public static async delete(
464
+ loginUser: LoginUser,
465
+ dbTransaction: any,
466
+ GroupCode: string,
467
+ ) {
468
+ // Part 1: Privilege Checking
469
+ const systemCode = ApplicationConfig.getComponentConfigValue('system-code');
470
+
471
+ const isPrivileged = await loginUser.checkPrivileges(
472
+ systemCode,
473
+ 'GROUP_DELETE',
474
+ );
475
+
476
+ if (!isPrivileged) {
477
+ throw new ClassError(
478
+ 'Group',
479
+ 'GroupErrMsg03',
480
+ 'You do not have the privilege to delete groups records.',
481
+ );
482
+ }
483
+ try {
484
+ const group = await Group.init(dbTransaction, GroupCode);
485
+
486
+ if (group.Status === 'Active') {
487
+ throw new ClassError(
488
+ 'Group',
489
+ 'GroupErrMsg03',
490
+ 'Active Group cant be deleted',
491
+ );
492
+ }
493
+
494
+ const relatedGroup = await Group.findAll(
495
+ 1,
496
+ Number.MAX_SAFE_INTEGER,
497
+ dbTransaction,
498
+ loginUser,
499
+ {
500
+ ParentGroupCode: GroupCode,
501
+ },
502
+ );
503
+
504
+ if (relatedGroup.Count > 0) {
505
+ const listOfRelatedGroup = relatedGroup.Groups.map((group) => {
506
+ return group.GroupCode;
507
+ });
508
+ throw new ClassError(
509
+ 'Group',
510
+ 'GroupErrMsg03',
511
+ `Group still has associated user group ${listOfRelatedGroup}`,
512
+ );
513
+ }
514
+
515
+ await Group._Repo.delete(GroupCode, dbTransaction);
516
+
517
+ const EntityValueBefore = {
518
+ GroupCode: group.GroupCode,
519
+ Name: group.Name,
520
+ Type: group.Type,
521
+ Description: group.Description,
522
+ ParentGroupCode: group.ParentGroupCode,
523
+ InheritParentPrivilegeYN: group.InheritParentPrivilegeYN,
524
+ InheritParentSystemAccessYN: group.InheritParentSystemAccessYN,
525
+ Status: group.Status,
526
+ CreatedById: group._CreatedById,
527
+ UpdatedById: group._UpdatedById,
528
+ CreatedAt: group._CreatedAt,
529
+ UpdatedAt: group._UpdatedAt,
530
+ };
531
+
532
+ const activity = new Activity();
533
+ activity.ActivityId = activity.createId();
534
+ activity.Action = ActionEnum.DELETE;
535
+ activity.Description = 'Delete Group';
536
+ activity.EntityType = 'Group';
537
+ activity.EntityId = group.ObjectId;
538
+ activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
539
+ activity.EntityValueAfter = JSON.stringify({});
540
+
541
+ await activity.create(loginUser.ObjectId, dbTransaction);
542
+
543
+ return { Message: 'Group removed.' };
544
+ } catch (error) {
545
+ throw error;
546
+ }
547
+ }
548
+
463
549
  public static async getSystemAccesses(
464
550
  loginUser: LoginUser,
465
551
  dbTransaction: any,