@tomei/sso 0.38.7 → 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.7",
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
  }
@@ -167,7 +171,8 @@ export class Group extends TreeNodeBase<Group> {
167
171
  }
168
172
 
169
173
  if (this.parent) {
170
- this._Path = (await this.parent.getPath(dbTransaction)) + '/' + this.Name;
174
+ this._Path =
175
+ (await this.parent.getPath(dbTransaction)) + '/' + this.GroupCode;
171
176
  return this._Path;
172
177
  }
173
178
  this._Path = this.GroupCode;
@@ -433,10 +438,12 @@ export class Group extends TreeNodeBase<Group> {
433
438
  //Break the path into array with oldGroupCode/ as separator;
434
439
  const path = children.Path.split(`${oldGroupCode}/`);
435
440
  //Retrive the last element of the array
436
- const childPath = path[path.length - 1];
437
- //Combine the childPath with this.Path
438
- children.Path = `${this.Path}/${childPath}`;
439
- 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
+ );
440
447
  });
441
448
  } catch (error) {
442
449
  throw error;
@@ -473,39 +480,38 @@ export class Group extends TreeNodeBase<Group> {
473
480
  );
474
481
  }
475
482
  try {
476
- const currentGroup = await Group.init(dbTransaction, group.GroupCode);
477
483
  if (group.NewGroupCode) {
478
484
  await Group.checkDuplicateGroupCode(dbTransaction, group.NewGroupCode);
479
485
  }
480
486
 
481
487
  const entityValueBefore = {
482
- GroupCode: currentGroup.GroupCode,
483
- Name: currentGroup.Name,
484
- Type: currentGroup.Type,
485
- Description: currentGroup.Description,
486
- ParentGroupCode: currentGroup.ParentGroupCode,
487
- InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
488
- InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
489
- Path: currentGroup.Path,
490
- Status: currentGroup.Status,
491
- CreatedById: currentGroup._CreatedById,
492
- UpdatedById: currentGroup._UpdatedById,
493
- CreatedAt: currentGroup._CreatedAt,
494
- 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,
495
501
  };
496
502
 
497
503
  let isPathChanged = false;
498
- const oldGroupCode = currentGroup.GroupCode;
504
+ const oldGroupCode = this.GroupCode;
499
505
  if (group.NewGroupCode) {
500
- currentGroup.GroupCode = group.NewGroupCode;
506
+ this.GroupCode = group.NewGroupCode;
501
507
  isPathChanged = true;
502
508
  }
503
509
 
504
510
  //Check if ParentGroupCode is changed or added
505
511
  if (
506
512
  (group.ParentGroupCode &&
507
- currentGroup.ParentGroupCode !== group.ParentGroupCode) ||
508
- (group.ParentGroupCode && !currentGroup.ParentGroupCode)
513
+ this.ParentGroupCode !== group.ParentGroupCode) ||
514
+ (group.ParentGroupCode && !this.ParentGroupCode)
509
515
  ) {
510
516
  const parentGroup = await Group.init(
511
517
  dbTransaction,
@@ -518,46 +524,43 @@ export class Group extends TreeNodeBase<Group> {
518
524
  'Parent Group Code not found',
519
525
  );
520
526
  }
521
- await currentGroup.setParent(parentGroup);
527
+ await this.setParent(parentGroup);
522
528
  //Check if ParentGroupCode is removed
523
529
  isPathChanged = true;
524
- } else if (!group.ParentGroupCode && currentGroup.ParentGroupCode) {
525
- await currentGroup.setParent(null);
530
+ } else if (!group.ParentGroupCode && this.ParentGroupCode) {
531
+ await this.setParent(null);
526
532
  isPathChanged = true;
527
533
  }
528
534
 
529
535
  if (isPathChanged) {
530
- await currentGroup.updateChildrenPath(oldGroupCode, dbTransaction);
536
+ await this.updateChildrenPath(oldGroupCode, dbTransaction);
531
537
  }
532
538
 
533
- currentGroup.Name = group?.Name || currentGroup.Name;
534
- currentGroup.Type = group?.Type || currentGroup.Type;
535
- currentGroup.Description = group?.Description || currentGroup.Description;
536
- currentGroup.ParentGroupCode =
537
- group?.ParentGroupCode || currentGroup.ParentGroupCode;
538
- currentGroup.InheritParentPrivilegeYN =
539
- group?.InheritParentPrivilegeYN ||
540
- currentGroup.InheritParentPrivilegeYN;
541
- currentGroup.InheritParentSystemAccessYN =
542
- group?.InheritParentSystemAccessYN ||
543
- currentGroup.InheritParentSystemAccessYN;
544
- currentGroup.Status = group?.Status || currentGroup.Status;
545
- currentGroup._UpdatedById = loginUser.UserId;
546
- 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();
547
550
 
548
551
  await Group._Repo.update(
549
552
  {
550
- GroupCode: currentGroup.GroupCode,
551
- Name: currentGroup.Name,
552
- Type: currentGroup.Type,
553
- Description: currentGroup.Description,
554
- ParentGroupCode: currentGroup.ParentGroupCode,
555
- InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
556
- InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
557
- Status: currentGroup.Status,
558
- Path: currentGroup._Path,
559
- UpdatedById: currentGroup._UpdatedById,
560
- 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,
561
564
  },
562
565
  {
563
566
  where: {
@@ -568,19 +571,19 @@ export class Group extends TreeNodeBase<Group> {
568
571
  );
569
572
 
570
573
  const entityValueAfter = {
571
- GroupCode: currentGroup.GroupCode,
572
- Name: currentGroup.Name,
573
- Type: currentGroup.Type,
574
- Description: currentGroup.Description,
575
- ParentGroupCode: currentGroup.ParentGroupCode,
576
- InheritParentPrivilegeYN: currentGroup.InheritParentPrivilegeYN,
577
- InheritParentSystemAccessYN: currentGroup.InheritParentSystemAccessYN,
578
- Status: currentGroup.Status,
579
- Path: currentGroup._Path,
580
- CreatedById: currentGroup._CreatedById,
581
- UpdatedById: currentGroup._UpdatedById,
582
- CreatedAt: currentGroup._CreatedAt,
583
- 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,
584
587
  };
585
588
 
586
589
  const activity = new Activity();
@@ -593,7 +596,7 @@ export class Group extends TreeNodeBase<Group> {
593
596
  activity.EntityValueAfter = JSON.stringify(entityValueAfter);
594
597
  await activity.create(loginUser.ObjectId, dbTransaction);
595
598
 
596
- return currentGroup;
599
+ return this;
597
600
  } catch (error) {
598
601
  throw error;
599
602
  }