All files / src/models flow-persona.model.ts

67.44% Statements 29/43
0% Branches 0/9
25% Functions 2/8
65.85% Lines 27/41

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   216x 1x   216x 1x     1x                                     1x     1x     1x                                    
import { belongsTo, hasOne, model, property } from '@loopback/repository';
import { Expose, Transform } from 'class-transformer';
import { BaseEntity, Company, Persona, User } from '.';
import { NeededInfo } from '../types';
import { DateUtils } from '../utils/date';
import { Flow } from './flow.model';
import { Status } from './status';
import { TimeZoneTransform } from '@logchain/decorators';
@model({
  settings: {
    postgresql: { table: 'flows_persona' },
    foreignKeys: {
      fk_flows_persona_flows_id: {
        name: 'fk_flows_persona_flows_id',
        entity: 'Flow',
        entityKey: 'id',
        foreignKey: 'flow_id',
        onDelete: 'CASCADE',
        onUpdate: 'RESTRICT'
      },
    },
  },
})
export class FlowPersona extends BaseEntity {
  @belongsTo(() => Flow, { name: 'flow' })
  flow_id: number;
 
  @Expose()
  @property({
    type: 'string',
    jsonSchema: {
      maxLength: 500,
    },
  })
  name?: string;
 
  @Expose()
  @property({
    type: 'number',
  })
  persona_id: number;
 
  @property({
    type: 'number',
  })
  company_id: number;
 
  @Expose()
  @property({
    type: 'number',
  })
  order: number;
 
  @Expose()
  @property({
    type: 'number',
    default: Status.FlowPersona.WaitToValidate,
    jsonSchema: {
      enum: Object.values(Status.FlowPersona),
    },
  })
  status: number;
 
  @property({
    type: 'date',
    defaultFn: 'now',
  })
  @TimeZoneTransform()
  created_date: Date;
 
  @belongsTo(() => User, { name: 'creator' })
  created_by: number;
 
  @property({
    type: 'date',
    defaultFn: 'now',
  })
  @TimeZoneTransform()
  modified_date: Date;
 
  @Expose()
  @property({
    type: 'date',
  })
  @TimeZoneTransform()
  validated_date: Date;
 
  @property({
    type: 'object',
    postgresql: {
      dataType: 'jsonb',
    },
  })
  needed_info: NeededInfo;
 
  @belongsTo(() => User, { name: 'modifier' })
  modified_by?: number;
 
  @hasOne(() => Persona, { keyTo: 'id', keyFrom: 'persona_id', name: 'persona' })
  persona: Persona;
 
  @hasOne(() => Company, { keyTo: 'id', keyFrom: 'company_id', name: 'company' })
  company: Company;
 
  @Expose()
  status_name() {
    if (typeof this.status === 'undefined') {
      return;
    }
 
    switch (this.status) {
      case Status.FlowPersona.WaitToValidate:
        return 'For Validation';
      case Status.FlowPersona.Validated:
      case Status.FlowPersona.Live:
        return 'Validated';
      case Status.FlowPersona.Rejected:
        return 'Rejected';
      default:
        break;
    }
  }
 
  @Expose()
  groups: string;
 
  @Expose()
  color: string;
 
  @Expose()
  icon() {
    if (!this.persona) {
      return;
    }
 
    return `${this.persona.title.toLowerCase().replace(/ /g, '-')}-icon`;
  }
 
  constructor(data?: Partial<FlowPersona>) {
    super(data);
  }
}
 
export interface FlowPersonaRelations {
  // describe navigational properties here
}
 
export type FlowPersonaWithRelations = FlowPersona & FlowPersonaRelations;