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

88.57% Statements 31/35
0% Branches 0/2
77.78% Functions 7/9
87.88% Lines 29/33

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 1581x 1x 1x   1x 1x 1x 1x           1x   92x           1x               1x               1x         92x                 1x                 1x                                                       1x           1x           1x   92x 1x           1x   92x 1x   92x 1x   92x 1x   92x 1x                                                                        
import {belongsTo, hasMany, model, property} from '@loopback/repository';
import {BaseEntity, Company, TradeLane, User} from '.';
import {Constants} from '../configs';
import {Action, Documents, GroupDetail, Stats} from '../types';
import {FlowDefaultGroup} from './flow-default-group.model';
import {FlowDefaultJourneyPoint} from './flow-default-journey-point.model';
import {FlowDefaultPersona} from './flow-default-persona.model';
import {Status} from './status';
@model({
  settings: {
    postgresql: {table: 'flows_default'},
  },
})
export class FlowDefault extends BaseEntity {
  @belongsTo(
    () => TradeLane,
    {name: 'trade_lane'},
    {
      type: 'number',
    },
  )
  trade_lane_id: number;
 
  @property({
    type: 'string',
    jsonSchema: {
      maxLength: 100,
    },
  })
  name: string;
 
  @property({
    type: 'string',
    jsonSchema: {
      nullable: true,
    },
  })
  description: string;
 
  // 0. That means all companies can see this flow.
  // Otherwise, this will be the company id.
  @belongsTo(
    () => Company,
    {name: 'company'},
    {
      jsonSchema: {
        description:
          '- (0) That means all companies can see this flow. Otherwise, this will be the company id.',
      },
    },
  )
  company_access: number;
 
  @property({
    type: 'number',
    default: Status.FlowDefault.New,
    jsonSchema: {
      enum: Object.values(Status.FlowDefault),
    },
  })
  status: number;
 
  @property({
    type: 'object',
    postgresql: {
      dataType: 'jsonb',
    },
    default: {groups: 0, steps: 0, personas: 0, forms: 0, documents: 0},
    jsonSchema: {
      properties: {
        groups: {
          type: 'number',
        },
        steps: {
          type: 'number',
        },
        forms: {
          type: 'number',
        },
        documents: {
          type: 'number',
        },
        personas: {
          type: 'number',
        },
      },
    },
  })
  stats: Stats;
 
  @property({
    type: 'number',
    required: true,
  })
  step: number;
 
  @property({
    type: 'date',
    defaultFn: 'now',
  })
  created_date: Date;
 
  @belongsTo(() => User, {name: 'creator'})
  created_by: number;
 
  @property({
    type: 'date',
    defaultFn: 'now',
  })
  modified_date: Date;
 
  @belongsTo(() => User, {name: 'modifier'})
  modified_by?: number;
 
  @hasMany(() => FlowDefaultGroup, {keyTo: 'flow_default_id'})
  groups: FlowDefaultGroup[];
 
  @hasMany(() => FlowDefaultJourneyPoint, {keyTo: 'flow_default_id'})
  journey_points: FlowDefaultJourneyPoint[];
 
  @hasMany(() => FlowDefaultPersona, {keyTo: 'flow_default_id'})
  personas: FlowDefaultPersona[];
 
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  unique_persona?: any[];
 
  group_details?: GroupDetail[];
 
  journey_detail?: FlowDefaultJourneyPoint;
 
  allowed_actions?: Action[];
  allowed_documents?: Documents[];
  steps_state?: boolean[];
 
  constructor(data?: Partial<FlowDefault>) {
    super(data);
  }
 
  /**
   * Return next step.
   */
  getNextStep(): number {
    if (!this.step) {
      return Constants.FlowStep.One;
    }
 
    return ++this.step;
  }
}
 
export interface FlowDefaultRelations {
  // describe navigational properties here
  creator?: User;
  modifier?: User;
}
 
export type FlowDefaultWithRelations = FlowDefault & FlowDefaultRelations;