All files / components/user-group user-group.ts

100% Statements 40/40
100% Branches 4/4
100% Functions 6/6
100% Lines 40/40

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 82 83 84 85 86 87 88 89 90 911x 1x     1x 5x 5x                             2x       2x       2x       2x     1x     5x 5x 3x 3x 3x 3x 3x 3x   3x 3x 3x 3x         2x 2x 2x 2x       2x 1x 1x 1x 1x 1x   1x   1x 1x 1x 1x   1x             1x   1x        
import { ClassError, ObjectBase } from '@tomei/general';
import { UserGroupRepository } from './user-group.repository';
import { IUserGroupAttr } from '../../interfaces/user-group.interface';
 
export class UserGroup extends ObjectBase {
  ObjectType = 'UserGroup';
  TableName = 'sso_UserGroup';
  ObjectName: string;
  ObjectId: string;
  UserGroupId: number;
  UserId: number;
  GroupCode: string;
  InheritGroupPrivilegeYN: string;
  InheritGroupSystemAccessYN: string;
  Status: string;
  private _CreatedAt: Date;
  private _UpdatedAt: Date;
  private _CreatedById: number;
  private _UpdatedById: number;
 
  get CreatedAt() {
    return this._CreatedAt;
  }
 
  get UpdatedAt() {
    return this._UpdatedAt;
  }
 
  get CreatedById() {
    return this._CreatedById;
  }
 
  get UpdatedById() {
    return this._UpdatedById;
  }
 
  private static _Repository = new UserGroupRepository();
 
  private constructor(userGroupAttr?: IUserGroupAttr) {
    super();
    if (userGroupAttr) {
      this.UserGroupId = userGroupAttr.UserGroupId;
      this.UserId = userGroupAttr.UserId;
      this.GroupCode = userGroupAttr.GroupCode;
      this.Status = userGroupAttr.Status;
      this.InheritGroupPrivilegeYN = userGroupAttr.InheritGroupPrivilegeYN;
      this.InheritGroupSystemAccessYN =
        userGroupAttr.InheritGroupSystemAccessYN;
      this._CreatedById = userGroupAttr.CreatedById;
      this._CreatedAt = userGroupAttr.CreatedAt;
      this._UpdatedById = userGroupAttr.UpdatedById;
      this._UpdatedAt = userGroupAttr.UpdatedAt;
    }
  }
 
  static async init(dbTransaction: any, UserGroupId?: number) {
    try {
      const userGroup = new UserGroup();
      if (UserGroupId) {
        const userGroupAttr = await this._Repository.findOne({
          where: { UserGroupId },
          transaction: dbTransaction,
        });
        if (userGroupAttr) {
          userGroup.UserGroupId = userGroupAttr.UserGroupId;
          userGroup.UserId = userGroupAttr.UserId;
          userGroup.GroupCode = userGroupAttr.GroupCode;
          userGroup.Status = userGroupAttr.Status;
          userGroup.InheritGroupPrivilegeYN =
            userGroupAttr.InheritGroupPrivilegeYN;
          userGroup.InheritGroupSystemAccessYN =
            userGroupAttr.InheritGroupSystemAccessYN;
          userGroup._CreatedById = userGroupAttr.CreatedById;
          userGroup._CreatedAt = userGroupAttr.CreatedAt;
          userGroup._UpdatedById = userGroupAttr.UpdatedById;
          userGroup._UpdatedAt = userGroupAttr.UpdatedAt;
        } else {
          throw new ClassError(
            'UserGroup',
            'UserGroupErrMsg00',
            'UserGroup Not Found',
          );
        }
      }
      return userGroup;
    } catch (error) {
      throw error;
    }
  }
}