All files / src/controllers/public entry.controller.ts

78.95% Statements 15/19
100% Branches 0/0
0% Functions 0/2
76.47% Lines 13/17

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 731x 1x 1x   1x 1x 1x 1x 1x 1x         1x                               1x                 1x                                                       1x          
import { authenticate } from '@loopback/authentication';
import { Constructor, service } from '@loopback/core';
import { get, oas, param } from '@loopback/rest';
 
import { createBaseControllerFactory, BaseController, MixinOptions, ExtendOptions } from '@logchain/controllers';
import { buildResponseObjectById } from '@logchain/apidefs';
import { Module, Constants, CONTENT_TYPE } from '@logchain/configs';
import { EntryDto } from '@logchain/dtos';
import { Entry } from '@logchain/models';
import { EntryService } from '@logchain/services';
 
/**
 * Define the MixinOptions
 */
const options: MixinOptions = {
  basePath: '/entries',
  modelClass: Entry,
  modelDtoClass: EntryDto,
  admin: false,
  schemaOptions: {
    find: {
      authorize: {
        resource: Module.Intermodal.EntryMgmt,
        scopes: [Constants.AccessScope.Retrieve],
      },
    },
  },
};
 
 
const extendOptions: ExtendOptions = {
  isExtendRead: true,
}
 
/**
 * Entry controller
 */
@oas.tags('Entry')
@authenticate('aws-cognito')
export class EntryController extends createBaseControllerFactory<Entry, Constructor<BaseController>>(BaseController, options, extendOptions) {
  constructor(
    @service(EntryService)
    public selfService: EntryService,
  ) {
    super();
  }
 
  /**
   * Get Entry Record by Type
   * @param type The type of EntryRecords
   * @returns EntryRecords list
   */
  @get(`${options.basePath}/{id}/references`, {
    responses: {
      '200': {
        description: `Reference documents of entry.`,
        content: {
          [CONTENT_TYPE.JSON]: {
            schema: buildResponseObjectById(
              options.modelDtoClass,
              options.admin,
            ),
          },
        },
      },
    },
  })
  async getReferenceDocuments(@param.path.integer('id') id: number) {
    this.selfService.ensureRightAccessRecord();
    return this.selfService.getReferenceDocuments(id);
  }
}