All files / src/models entry-record.model.ts

92.5% Statements 37/40
100% Branches 0/0
57.14% Functions 4/7
92.11% Lines 35/38

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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 1951x 1x 1x 1x     1x   1x                               1x           1x   162x 1x       1x                 1x               1x               1x                         1x               1x               1x   162x 1x   162x 1x                 1x           1x           1x             1x               1x   162x 1x             1x         1x           1x           1x           1x           1x       1x                                    
import { AnyObject, belongsTo, hasMany, model, property } from '@loopback/repository';
import { Exclude, Transform } from 'class-transformer';
import { BaseEntity, Entry, EntryRecordGroup, FilesMapping, FlowAction, User } from '.';
import { Constants } from '../configs';
import { BlockchainInfo } from '../types';
import { DateUtils } from '../utils/date';
import { Status } from './status';
import { VerificationView } from './views';
import { TimeZoneTransform } from '@logchain/decorators';
@model({
  settings: {
    postgresql: { table: 'entry_records' },
    foreignKeys: {
      fk_entry_records_entries_id: {
        name: 'fk_entry_records_entries_id',
        entity: 'Entry',
        entityKey: 'id',
        foreignKey: 'entry_id',
        onDelete: 'CASCADE',
        onUpdate: 'RESTRICT'
      },
    },
  },
})
export class EntryRecord extends BaseEntity implements BlockchainInfo {
  @property({
    type: 'number',
    id: true,
    generated: true,
  })
  id: number;
 
  @belongsTo(() => Entry, { name: 'entry' })
  entry_id: number;
 
  @Exclude()
  @belongsTo(() => FlowAction, { name: 'flow_action' })
  flow_action_id: number;
 
  @property({
    type: 'number',
    required: true,
    jsonSchema: {
      enum: Object.values(Constants.EntryRecordType),
    },
  })
  type: number;
 
  @property({
    type: 'string',
    jsonSchema: {
      nullable: true,
    },
  })
  remark: string;
 
  @property({
    type: 'number',
    jsonSchema: {
      enum: Object.values(Status.EntryRecordInspect),
    },
  })
  inspection_result: number;
 
  @property({
    type: 'number',
    jsonSchema: {
      nullable: true,
      enum: [
        Status.ActionAfterCancelled.ContinueFlow,
        Status.ActionAfterCancelled.StopContainer,
        Status.ActionAfterCancelled.NewAction,
      ],
    },
  })
  cancelled_action: number;
 
  @property({
    type: 'string',
    jsonSchema: {
      nullable: true,
    },
  })
  cancelled_reason: string;
 
  @property({
    type: 'number',
    jsonSchema: {
      enum: Object.values(Status.EntryRecord),
    },
  })
  planned_activity: number;
 
  @belongsTo(() => User, { name: 'driven' })
  driven_by: number;
 
  @belongsTo(() => User, { name: 'inspected' })
  inspected_by: number;
 
  @property({
    type: 'date', 
    nullable: true,
    jsonSchema: {
      nullable: true,
    },   
  })
  actual_date: Date;
 
  @property({
    type: 'date',
    defaultFn: 'now',  
  })
  system_actual_date: Date;
 
  @property({
    type: 'date',
    defaultFn: 'now',
  })
  created_date: Date;
 
  @property({
    type: 'date',
    defaultFn: 'now',
  })
  @TimeZoneTransform()
  modified_date: Date;
 
  @property({
    type: 'number',
    jsonSchema: {
      enum: Object.values(Constants.EntryRecordMethod),
    },
  })
  method: number;
 
  @hasMany(() => EntryRecordGroup, { keyTo: 'entry_record_id' })
  entry_record_groups: EntryRecordGroup[];
 
  entry: Entry;
 
  expected_date: Date;
 
  @property()
  is_pdf_created: boolean;
 
  @property({
    type: 'number',
  })
  pdf_attempt: number;
 
  @Exclude()
  @property({
    type: 'string',
  })
  uri: string;
 
  @Exclude()
  @property({
    type: 'string',
  })
  version: string;
 
  @Exclude()
  @property({
    type: 'string',
  })
  hash: string;
 
  @Exclude()
  @property({
    type: 'string',
  })
  blockchain_tx: string;
 
  @Exclude()
  @belongsTo(() => User, { name: 'override_by' })
  override_by_id: number;
 
  constructor(data?: Partial<EntryRecord>) {
    super(data);
  }
}
 
export interface EntryRecordRelations {
  // describe navigational properties here
  driven?: User;
  inspected?: User;
  checklists?: AnyObject[];
  additional_documents?: FilesMapping[];
  vehicle_no?: string;
  verification?: VerificationView;
}
 
export type EntryRecordWithRelations = EntryRecord & EntryRecordRelations;