All files / components/group group.ts

96.77% Statements 30/31
78.57% Branches 22/28
100% Functions 6/6
96.77% Lines 30/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 821x 1x       1x       1x                           1x     1x       1x       1x       1x       1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x         3x 3x 3x     2x 1x   1x         2x                
import { ClassError, HashTable, ObjectBase } from '@tomei/general';
import { GroupRepository } from './group.repository';
import { IGroupAttr } from '../../interfaces/group.interface';
import { GroupTypeEnum } from 'enum';
 
export class Group extends ObjectBase {
  ObjectId: string;
  ObjectName: string;
  TableName: 'sso_Group';
  ObjectType = 'Group';
 
  GroupCode: string;
  Name: string;
  Description: string;
  Type: GroupTypeEnum;
  ParentGroupCode: string;
  InheritParentPrivilegeYN: string;
  InheritParentSystemAccessYN: string;
  Status: string;
  private _CreatedById: number;
  private _CreatedAt: Date;
  private _UpdatedById: number;
  private _UpdatedAt: Date;
  private static _Repo = new GroupRepository();
 
  get CreatedById(): number {
    return this._CreatedById;
  }
 
  get CreatedAt(): Date {
    return this._CreatedAt;
  }
 
  get UpdatedById(): number {
    return this._UpdatedById;
  }
 
  get UpdatedAt(): Date {
    return this._UpdatedAt;
  }
 
  private constructor(groupAttr?: IGroupAttr) {
    super();
    if (groupAttr) {
      this.GroupCode = groupAttr.GroupCode;
      this.Name = groupAttr.Name;
      this.Description = groupAttr?.Description;
      this.Type = groupAttr?.Type;
      this.ParentGroupCode = groupAttr?.ParentGroupCode;
      this.InheritParentPrivilegeYN = groupAttr?.InheritParentPrivilegeYN;
      this.InheritParentSystemAccessYN = groupAttr?.InheritParentSystemAccessYN;
      this.Status = groupAttr?.Status;
      this._CreatedById = groupAttr.CreatedById;
      this._CreatedAt = groupAttr.CreatedAt;
      this._UpdatedById = groupAttr.UpdatedById;
      this._UpdatedAt = groupAttr.UpdatedAt;
    }
  }
 
  public static async init(dbTransaction: any, GroupCode?: string) {
    try {
      if (GroupCode) {
        const group = await Group._Repo.findByPk(GroupCode, {
          transaction: dbTransaction,
        });
        if (group) {
          return new Group(group);
        } else {
          throw Error('Group not found');
        }
      }
      return new Group();
    } catch (error) {
      throw new ClassError(
        'Group',
        'GroupErrMsg01',
        'Failed To Initialize Group',
      );
    }
  }
}