All files / src/models category.model.ts

86.96% Statements 20/23
100% Branches 0/0
25% Functions 1/4
85.71% Lines 18/21

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 1061x 1x 1x 1x 1x             1x 76x 1x                     1x               1x                 1x                 1x                 1x                             1x             1x     1x           1x     1x                        
import { belongsTo, model, property } from '@loopback/repository';
import { BaseEntity } from './base-entity';
import { Constants } from '@logchain/configs';
import { Status } from './status';
import { Company, User } from '.';
 
@model({
  settings: {
    postgresql: { table: 'categories' },
  },
})
export class Category extends BaseEntity {
  @belongsTo(() => Company, {name: 'company'})
  company_id: number;
 
  @property({
    type: 'string',
    required: true,
    maxLength: 100,
    jsonSchema: {
      minLength: 1,
      maxLength: 100,
    },
  })
  name: string;
 
  @property({
    type: 'string',
    jsonSchema: {
      nullable: true,
    },
  })
  description?: string;
 
  @property({
    type: 'number',
    jsonSchema: {
      maxLength: 1,
      default: Constants.CategoryType.All,
    },
  })
  type?: number;
 
  @property({
    type: 'array',
    itemType: 'number',
    postgresql: {
      dataType: 'varchar[]',
    },
  })
  type_detail: number[];
 
  @property({
    type: 'array',
    itemType: 'number',
    postgresql: {
      dataType: 'varchar[]',
    },
  })
  granted_users: number[];
 
  @property({
    type: 'number',
    required: true,
    default: Status.Category.Active,
    jsonSchema: {
      enum: [
        Status.Category.Inactive,
        Status.Category.Active,
      ],
      default: Status.Category.Active,
      nullable: false,
    },
  })
  status: number;
 
  @property({
    type: 'date',
    required: true,
    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;
 
  constructor(data?: Partial<Category>) {
    super(data);
  }
}
 
export interface CategoryRelations {
  // describe navigational properties here
}
 
export type CategoryWithRelations = Category & CategoryRelations;