All files / src/models role-rights.model.ts

95% Statements 19/20
100% Branches 0/0
66.67% Functions 2/3
94.44% Lines 17/18

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 1211x 1x 1x 1x 1x                                                       1x         1x   154x 1x   154x 1x                     1x                     1x                     1x                     1x                     1x                   1x                        
import {belongsTo, hasOne, model, property} from '@loopback/repository';
import {Feature} from '.';
import {Constants} from '../configs';
import {BaseEntity} from './base-entity';
import {Role} from './role.model';
 
@model({
  settings: {
    postgresql: {table: 'role_rights'},
    indexes: {
      feature_role_unique: {
        keys: {
          feature_id: 1,
          role_id: 1,
        },
        options: {
          unique: true,
        },
      },
    },
    foreignKeys: {
      fk_role_rights_role_id: {
        name: 'fk_role_rights_role_id',
        entity: 'Role',
        entityKey: 'id',
        foreignKey: 'role_id',
        onDelete: 'CASCADE',
        onUpdate: 'CASCADE'
      },
    },
  },
})
export class RoleRights extends BaseEntity {
  @property({
    type: 'number',
    required: true,
  })
  feature_id: number;
 
  @hasOne(() => Feature, {keyTo: 'id', keyFrom: 'feature_id'})
  feature: Feature;
 
  @belongsTo(() => Role, {name: 'role'})
  role_id: number;
 
  @property({
    type: 'number',
    required: true,
    default: Constants.Access.Denied,
    name: 'create',
    jsonSchema: {
      enum: Object.values(Constants.Access),
    },
  })
  allow_create: number;
 
  @property({
    type: 'number',
    required: true,
    default: Constants.Access.Denied,
    name: 'retrieve',
    jsonSchema: {
      enum: Object.values(Constants.Access),
    },
  })
  allow_retrieve: number;
 
  @property({
    type: 'number',
    required: true,
    default: Constants.Access.Denied,
    name: 'update',
    jsonSchema: {
      enum: Object.values(Constants.Access),
    },
  })
  allow_update: number;
 
  @property({
    type: 'number',
    required: true,
    default: Constants.Access.Denied,
    name: 'delete',
    jsonSchema: {
      enum: Object.values(Constants.Access),
    },
  })
  allow_delete: number;
 
  @property({
    type: 'number',
    required: true,
    default: Constants.Access.Denied,
    name: 'validate',
    jsonSchema: {
      enum: Object.values(Constants.Access),
    },
  })
  allow_validate: number;
 
  @property({
    type: 'number',
    default: Constants.Access.Denied,
    name: 'override',
    jsonSchema: {
      enum: Object.values(Constants.Access),
    },
  })
  allow_override: number;
 
  constructor(data?: Partial<RoleRights>) {
    super(data);
  }
}
 
export interface RoleRightsRelations {
  // describe navigational properties here
}
 
export type RoleRightsWithRelations = RoleRights & RoleRightsRelations;