All files / src/dtos profile.dto.ts

73.81% Statements 31/42
0% Branches 0/8
0% Functions 0/5
74.36% Lines 29/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 118 119 120 1211x 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            
import { model } from '@loopback/repository';
import { Exclude, Expose, Transform, Type } from 'class-transformer';
import { CompanyDto } from '.';
import { Role, User, UserSetting } from '../models';
import { DateUtils } from '../utils/date';
import { UserDto } from './user.dto';
import { Constants } from '@logchain/configs';
import { TimeZoneTransform, UserTransform } from '@logchain/decorators';
 
class IdentityInfo {
  valid_from: Date;
  valid_to: Date;
  issuer_cn: string;
  subject_cn: string;
}
 
/**
 * User DTO
 */
@Exclude()
@model({ name: 'UserDto' })
export class ProfileDto extends User {
  @Expose({ groups: ['private'] })
  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;
 
  @Expose()
  languages: object[] = Constants.Locales;
 
  /**
   * 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()
  status: number;
 
  @Expose()
  status_name() {
    switch (this.status) {
      case 0:
        return 'Invite';
      case 1:
        return 'Inactive';
      case 2:
        return 'Active';
      default:
    }
  }
 
  @Expose()
  @TimeZoneTransform()
  created_date: Date;
 
  @Expose()
  @TimeZoneTransform()
  login_date?: Date;
 
  @UserTransform('created_name', ['single'])
  creator?: UserDto;
 
  @UserTransform('modified_name', ['single'])
  modifier?: UserDto;
 
  @Expose()
  @TimeZoneTransform()
  modified_date: Date;
 
  @Expose()
  @Type(() => IdentityInfo)
  blockchain_identity?: IdentityInfo;
 
  @Expose({ groups: ['single'] })
  settings: UserSetting;
 
  constructor(data?: Partial<ProfileDto>) {
    super(data);
  }
}