All files / src/dtos role.dto.ts

69.7% Statements 23/33
0% Branches 0/18
0% Functions 0/6
67.74% Lines 21/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 82 83 84 85 86 87 881x 1x 1x 1x   1x       1x   1x     1x     1x     1x     1x     1x     1x     1x       1x       1x           1x                   1x                 1x     1x               1x                      
import { model, property } from '@loopback/repository';
import { Exclude, Expose, Transform, Type } from 'class-transformer';
import { RoleRightsDto, UserDto } from '.';
import { Role, Status } from '../models';
import { DateUtils } from '../utils/date';
import { TimeZoneTransform, UserTransform } from '@logchain/decorators';
 
@Exclude()
@model({ name: 'Role' })
export class RoleDto extends Role {
  @Expose()
  id: number;
 
  @Expose()
  company_id: number;
 
  @Expose()
  company_name: string;
 
  @Expose()
  collar_type: number;
 
  @Expose()
  collar_type_name: number;
 
  @Expose()
  name: string;
 
  @Expose()
  description: string;
 
  @Expose()
  status: boolean;
 
  @Expose({ groups: ['private'] })
  @TimeZoneTransform()
  created_date: Date;
 
  @Expose({ groups: ['private'] })
  @TimeZoneTransform()
  modified_date: Date;
 
  @Expose({ groups: ['private'] })
  @property({
    type: 'number',
  })
  user_count() {
    if (typeof this.users !== 'undefined') {
      return this.users?.length;
    }
  }
 
  @Expose({ groups: ['private'] })
  @property({
    type: 'number',
  })
  user_active() {
    if (typeof this.users !== 'undefined') {
      return this.users.filter(user => {
        return user.status === Status.User.Active;
      }).length;
    }
  }
 
  @UserTransform('created_name', ['single'])
  creator?: UserDto;
 
  @UserTransform('modified_name', ['single'])
  modifier?: UserDto;
 
  @Type(() => RoleRightsDto)
  @Expose({ groups: ['private'] })
  @property({
    type: 'array',
    itemType: RoleRightsDto,
  })
  role_details: RoleRightsDto[];
 
  constructor(data?: Partial<RoleDto>) {
    if (data?.role_rights) {
      data.role_details = data?.role_rights.map(rr => {
        return new RoleRightsDto(rr);
      });
    }
    super(data);
  }
}