All files / src/dtos user.dto.ts

86.05% Statements 37/43
0% Branches 0/4
20% Functions 1/5
84.62% Lines 33/39

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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 1181x 1x 1x 1x   1x 1x             1x   1x     1x     1x       1x     1x     1x     1x               1x     1x               1x     1x                 1x     1x     1x       1x       1x     1x       1x     1x       1x               1x   1x     1x     1x     1x   4x      
import { model } from '@loopback/repository';
import { Exclude, Expose, Transform, Type } from 'class-transformer';
import { CompanyDto, UserActivityDto } from '.';
import { Role, User } from '../models';
import { DateUtils } from '../utils/date';
import { UserView } from '@logchain/models/views';
import { TimeZoneTransform, UserTransform } from '@logchain/decorators';
 
/**
 * User DTO
 */
@Exclude()
@model({ name: 'UserDto' })
export class UserDto extends UserView {
  @Expose()
  id: number;
 
  @Expose()
  identifier: string;
 
  @Expose()
  name: string;
 
  @Expose()
  @Type(() => CompanyDto)
  company?: CompanyDto;
 
  @Expose()
  role: Role;
 
  @Expose()
  avatar: string;
 
  @Expose()
  contact_number: string;
 
  /**
   * Alias of contact_email
   */
  phone_number: string;
 
  @Expose()
  contact_email: string;
 
  @Expose()
  language: string;
 
  /**
   * Alias of contact_email
   */
  email: string;
 
  @Expose()
  is_admin: boolean;
 
  @Expose()
  is_admin_name() {
    if (typeof this.is_admin === 'undefined') {
      return;
    }
 
    return this.is_admin ? 'Admin' : 'Regular User';
  }
 
  @Expose()
  blockchain_status: number;
 
  @Expose()
  status: number;
 
  @Expose()
  status_name: string;
 
  @Expose()
  @TimeZoneTransform()
  created_date: Date;
 
  @Expose()
  @TimeZoneTransform()
  login_date?: Date;
 
  @UserTransform('created_name', ['single'])
  creator?: UserDto;
 
  @Expose()
  @TimeZoneTransform()
  modified_date: Date;
 
  @UserTransform('modified_name', ['single'])
  modifier?: UserDto;
 
  @Type(() => UserActivityDto)
  @Expose()
  activities: UserActivityDto[];
 
  constructor(data?: Partial<UserDto>) {
    super(data);
  }
}
 
@model({ name: 'UserForRequestDto' })
export class UserForRequestDto extends User {
  @Exclude()
  id: number;
 
  @Expose({ name: 'email' })
  contact_email: string;
 
  @Exclude()
  contact_number: string;
 
  @Exclude()
  email?: string;
  constructor(data?: Partial<UserDto>) {
    super(data);
  }
}