@tomei/sso 0.38.8 → 0.38.9

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.38.8",
3
+ "version": "0.38.9",
4
4
  "description": "Tomei SSO Package",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -72,6 +72,10 @@ export class Group extends TreeNodeBase<Group> {
72
72
  return this._UpdatedAt;
73
73
  }
74
74
 
75
+ get Path(): string {
76
+ return this._Path;
77
+ }
78
+
75
79
  set Path(value: string) {
76
80
  this._Path = value;
77
81
  }
@@ -434,10 +438,12 @@ export class Group extends TreeNodeBase<Group> {
434
438
  //Break the path into array with oldGroupCode/ as separator;
435
439
  const path = children.Path.split(`${oldGroupCode}/`);
436
440
  //Retrive the last element of the array
437
- const childPath = path[path.length - 1];
438
- //Combine the childPath with this.Path
439
- children.Path = `${this.Path}/${childPath}`;
440
- await children.update({ Path: path }, { transaction: dbTransaction });
441
+ const childPath = path[1];
442
+ //Combine the childPath with this.Path then save it to the children.Path
443
+ await children.update(
444
+ { Path: `${this._Path}/${childPath}` },
445
+ { transaction: dbTransaction },
446
+ );
441
447
  });
442
448
  } catch (error) {
443
449
  throw error;
@@ -474,39 +480,38 @@ export class Group extends TreeNodeBase<Group> {
474
480
  );
475
481
  }
476
482
  try {
477
- const currentGroup = await Group.init(dbTransaction, group.GroupCode);
478
483
  if (group.NewGroupCode) {
479
484
  await Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
480
485
  }
481
486
 
482
487
  const entityValueBefore = {
483
- GroupCode: currentGroup.GroupCode,
484
- Name: currentGroup.Name,
485
- Type: currentGroup.Type,
486
- Description: currentGroup.Description,
487
- ParentGroupCode: currentGroup.ParentGroupCode,
488
- InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
489
- InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
490
- Path: currentGroup.Path,
491
- Status: currentGroup.Status,
492
- CreatedById: currentGroup._CreatedById,
493
- UpdatedById: currentGroup._UpdatedById,
494
- CreatedAt: currentGroup._CreatedAt,
495
- UpdatedAt: currentGroup._UpdatedAt,
488
+ GroupCode: this.GroupCode,
489
+ Name: this.Name,
490
+ Type: this.Type,
491
+ Description: this.Description,
492
+ ParentGroupCode: this.ParentGroupCode,
493
+ InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
494
+ InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
495
+ Path: this.Path,
496
+ Status: this.Status,
497
+ CreatedById: this._CreatedById,
498
+ UpdatedById: this._UpdatedById,
499
+ CreatedAt: this._CreatedAt,
500
+ UpdatedAt: this._UpdatedAt,
496
501
  };
497
502
 
498
503
  let isPathChanged = false;
499
- const oldGroupCode = currentGroup.GroupCode;
504
+ const oldGroupCode = this.GroupCode;
500
505
  if (group.NewGroupCode) {
501
- currentGroup.GroupCode = group.NewGroupCode;
506
+ this.GroupCode = group.NewGroupCode;
502
507
  isPathChanged = true;
503
508
  }
504
509
 
505
510
  //Check if ParentGroupCode is changed or added
506
511
  if (
507
512
  (group.ParentGroupCode &&
508
- currentGroup.ParentGroupCode !== group.ParentGroupCode) ||
509
- (group.ParentGroupCode && !currentGroup.ParentGroupCode)
513
+ this.ParentGroupCode !== group.ParentGroupCode) ||
514
+ (group.ParentGroupCode && !this.ParentGroupCode)
510
515
  ) {
511
516
  const parentGroup = await Group.init(
512
517
  dbTransaction,
@@ -519,46 +524,43 @@ export class Group extends TreeNodeBase<Group> {
519
524
  'Parent Group Code not found',
520
525
  );
521
526
  }
522
- await currentGroup.setParent(parentGroup);
527
+ await this.setParent(parentGroup);
523
528
  //Check if ParentGroupCode is removed
524
529
  isPathChanged = true;
525
- } else if (!group.ParentGroupCode && currentGroup.ParentGroupCode) {
526
- await currentGroup.setParent(null);
530
+ } else if (!group.ParentGroupCode && this.ParentGroupCode) {
531
+ await this.setParent(null);
527
532
  isPathChanged = true;
528
533
  }
529
534
 
530
535
  if (isPathChanged) {
531
- await currentGroup.updateChildrenPath(oldGroupCode, dbTransaction);
536
+ await this.updateChildrenPath(oldGroupCode, dbTransaction);
532
537
  }
533
538
 
534
- currentGroup.Name = group?.Name || currentGroup.Name;
535
- currentGroup.Type = group?.Type || currentGroup.Type;
536
- currentGroup.Description = group?.Description || currentGroup.Description;
537
- currentGroup.ParentGroupCode =
538
- group?.ParentGroupCode || currentGroup.ParentGroupCode;
539
- currentGroup.InheritParentPrivilegeYN =
540
- group?.InheritParentPrivilegeYN ||
541
- currentGroup.InheritParentPrivilegeYN;
542
- currentGroup.InheritParentSystemAccessYN =
543
- group?.InheritParentSystemAccessYN ||
544
- currentGroup.InheritParentSystemAccessYN;
545
- currentGroup.Status = group?.Status || currentGroup.Status;
546
- currentGroup._UpdatedById = loginUser.UserId;
547
- currentGroup._UpdatedAt = new Date();
539
+ this.Name = group?.Name || this.Name;
540
+ this.Type = group?.Type || this.Type;
541
+ this.Description = group?.Description || this.Description;
542
+ this.ParentGroupCode = group?.ParentGroupCode || this.ParentGroupCode;
543
+ this.InheritParentPrivilegeYN =
544
+ group?.InheritParentPrivilegeYN || this.InheritParentPrivilegeYN;
545
+ this.InheritParentSystemAccessYN =
546
+ group?.InheritParentSystemAccessYN || this.InheritParentSystemAccessYN;
547
+ this.Status = group?.Status || this.Status;
548
+ this._UpdatedById = loginUser.UserId;
549
+ this._UpdatedAt = new Date();
548
550
 
549
551
  await Group._Repo.update(
550
552
  {
551
- GroupCode: currentGroup.GroupCode,
552
- Name: currentGroup.Name,
553
- Type: currentGroup.Type,
554
- Description: currentGroup.Description,
555
- ParentGroupCode: currentGroup.ParentGroupCode,
556
- InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
557
- InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
558
- Status: currentGroup.Status,
559
- Path: currentGroup._Path,
560
- UpdatedById: currentGroup._UpdatedById,
561
- UpdatedAt: currentGroup._UpdatedAt,
553
+ GroupCode: this.GroupCode,
554
+ Name: this.Name,
555
+ Type: this.Type,
556
+ Description: this.Description,
557
+ ParentGroupCode: this.ParentGroupCode,
558
+ InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
559
+ InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
560
+ Status: this.Status,
561
+ Path: this._Path,
562
+ UpdatedById: this._UpdatedById,
563
+ UpdatedAt: this._UpdatedAt,
562
564
  },
563
565
  {
564
566
  where: {
@@ -569,19 +571,19 @@ export class Group extends TreeNodeBase<Group> {
569
571
  );
570
572
 
571
573
  const entityValueAfter = {
572
- GroupCode: currentGroup.GroupCode,
573
- Name: currentGroup.Name,
574
- Type: currentGroup.Type,
575
- Description: currentGroup.Description,
576
- ParentGroupCode: currentGroup.ParentGroupCode,
577
- InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
578
- InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
579
- Status: currentGroup.Status,
580
- Path: currentGroup._Path,
581
- CreatedById: currentGroup._CreatedById,
582
- UpdatedById: currentGroup._UpdatedById,
583
- CreatedAt: currentGroup._CreatedAt,
584
- UpdatedAt: currentGroup._UpdatedAt,
574
+ GroupCode: this.GroupCode,
575
+ Name: this.Name,
576
+ Type: this.Type,
577
+ Description: this.Description,
578
+ ParentGroupCode: this.ParentGroupCode,
579
+ InheritParentPrivilegeYN: this.InheritParentPrivilegeYN,
580
+ InheritParentSystemAccessYN: this.InheritParentSystemAccessYN,
581
+ Status: this.Status,
582
+ Path: this._Path,
583
+ CreatedById: this._CreatedById,
584
+ UpdatedById: this._UpdatedById,
585
+ CreatedAt: this._CreatedAt,
586
+ UpdatedAt: this._UpdatedAt,
585
587
  };
586
588
 
587
589
  const activity = new Activity();
@@ -594,7 +596,7 @@ export class Group extends TreeNodeBase<Group> {
594
596
  activity.EntityValueAfter = JSON.stringify(entityValueAfter);
595
597
  await activity.create(loginUser.ObjectId, dbTransaction);
596
598
 
597
- return currentGroup;
599
+ return this;
598
600
  } catch (error) {
599
601
  throw error;
600
602
  }