All files / src/dtos entry.dto.ts

57.35% Statements 39/68
0% Branches 0/24
0% Functions 0/11
56.06% Lines 37/66

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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 1491x 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     1x     1x     1x     1x     1x                                                                                                  
import { AnyObject, model } from '@loopback/repository';
import { Exclude, Expose, Transform, Type } from 'class-transformer';
import { Constants } from '../configs';
import { Entry, Status } from '../models';
import { DateUtils } from '../utils/date';
import { CompanyRequestDto } from './company.dto';
import { UserDto } from './user.dto';
import { EntryRecordDto } from './entry-record.dto';
import { TimeZoneTransform, UserTransform } from '@logchain/decorators';
 
@Exclude()
@model({ name: 'EntryDto' })
export class EntryDto extends Entry {
  @Expose()
  id: number;
 
  @Expose()
  @Type(() => CompanyRequestDto)
  company: CompanyRequestDto;
 
  @Expose()
  location_id: number;
 
  @Expose()
  @Type(() => CompanyRequestDto)
  delivered_company: CompanyRequestDto;
 
  @Expose()
  flow_id: number;
 
  @Expose()
  @Type(() => CompanyRequestDto)
  company_other: CompanyRequestDto;
 
  @Expose()
  @Type(() => UserDto)
  delivered: UserDto;
 
  @Type(() => UserDto)
  @Expose()
  supervise?: UserDto;
 
  @Expose()
  company_other_type: number;
 
  @Expose()
  vehicle_no: string;
  @Expose()
  tank_no: string;
  @Expose()
  order_no: string;
  @Expose()
  driven_name?: string;
 
  @Expose()
  product_no: string;
 
  @Expose()
  status: number;
 
  @Expose()
  status_name: string;
 
  @Exclude()
  modified_by: number;
 
  @Exclude()
  created_by: number;
 
  @Expose()
  actual_date: Date;
 
  @Expose()
  expected_date: Date;
 
  @Expose()
  @TimeZoneTransform()
  created_date: Date;
 
  @Expose()
  @TimeZoneTransform()
  modified_date: Date;
 
  @UserTransform('created_name', ['single'])
  creator?: UserDto;
 
  @UserTransform('modified_name', ['single'])
  modifier?: UserDto;
 
  @Type(() => EntryRecordDto)
  entry_records: EntryRecordDto[];
 
  @Expose({ name: 'gate_in' })
  gate_in: { gate_in_id: number, inspection_result: number, cancelled_action: number }[];
 
  @Expose({ name: 'gate_out' })
  gate_out: { gate_out_id: number, inspection_result: number, cancelled_action: number }[];
 
  @Expose()
  ref_documents?: AnyObject[];
 
  constructor(data?: Partial<EntryDto>) {
    super(data);
    if (data?.entry_records) {
      const gate_in = data?.entry_records
        .filter(x => {
          return x.type === Constants.EntryRecordType.GateIn;
        })
        .map(x => ({
          gate_in_id: x.id,
          inspection_result: x.inspection_result,
          cancelled_action: x.cancelled_action,
        }));
      const gate_out = data?.entry_records
        .filter(x => {
          return x.type === Constants.EntryRecordType.GateOut;
        })
        .map(x => ({
          gate_out_id: x.id,
          inspection_result: x.inspection_result,
          cancelled_action: x.cancelled_action,
        }));
 
      this.gate_in = gate_in;
      this.gate_out = gate_out;
    }
    switch (data?.status) {
      case Status.Entries.New:
        this.status_name = 'New';
        break;
      case Status.Entries.EntryApproved:
        this.status_name = 'Entry Approved';
        break;
      case Status.Entries.EntryRejected:
        this.status_name = 'Entry Rejected';
        break;
      case Status.Entries.ExitCompleted:
        this.status_name = 'Exit Completed';
        break;
      case Status.Entries.ExitRejected:
        this.status_name = 'Exit Rejected';
        break;
      case Status.Entries.Cancelled:
        this.status_name = 'Cancelled';
        break;
    }
  }
}