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

76.19% Statements 16/21
100% Branches 0/0
0% Functions 0/2
73.68% Lines 14/19

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 861x 1x   1x   1x 1x 1x 1x 1x 1x 1x         1x                                         1x                       1x                                           1x                            
import { authorize } from '@loopback/authorization';
import { service, intercept } from '@loopback/core';
import { Where } from '@loopback/repository';
import { get, getWhereSchemaFor, param, ParameterObject, oas } from '@loopback/rest';
 
import { buildResponseObject, limitSpec, offsetSpec, qSpec, sortSpec } from '@logchain/apidefs';
import { Constants, Module } from '@logchain/configs';
import { BaseController, MixinOptions } from '@logchain/controllers';
import { EnsurePagingCorrectInterceptor } from '@logchain/interceptors';
import { BaseResponses, CalistaDropdown } from '@logchain/models';
import { RegulatoryService } from '@logchain/services';
import { authenticate } from '@loopback/authentication';
 
/**
 * Define the MixinOptions for find
 */
const options: MixinOptions = {
  basePath: '/regulatory',
  modelClass: CalistaDropdown,
  modelDtoClass: CalistaDropdown,
  admin: false,
  schemaOptions: {
    find: {
      authorize: {
        resource: Module.Regulatory.RegulatoryFiling,
        scopes: [Constants.AccessScope.Retrieve],
      },
      exclude: [
        'created_date',
      ],
    },
  },
};
 
/**
 * The calista dropdown code value
 */
const dropdownSpec: ParameterObject = {
  description: 'The calista dropdown code to query',
  required: true,
  name: 'dropdown_code',
  in: 'query',
  schema: {
    type: 'string',
  },
};
 
@oas.tags('Regulatory Calista Dropdown')
@authenticate('aws-cognito')
export class RegulatoryController extends BaseController {
  constructor(
    @service(RegulatoryService)
    public selfService: RegulatoryService,
  ) {
    super();
  }
 
  /**
   * Find list of dropdown based on query
   * @param offset The offset number
   * @param limit The limit number
   * @param sort The array order
   * @param where The query object
   */
  @get(`${options.basePath}-dropdown`, {
    responses: {
      '200': buildResponseObject(options.modelDtoClass, options.admin),
    },
  })
  @intercept(EnsurePagingCorrectInterceptor.BINDING_KEY)
  @authorize(options.schemaOptions['find'].authorize)
  async find(
    @param(offsetSpec) offset: number,
    @param(limitSpec) limit: number,
    @param(sortSpec) sort: Array<string>,
    @param(qSpec) q: string,
    @param.query.object('where', getWhereSchemaFor(options.modelClass))
    where: Where<CalistaDropdown>,
    @param(dropdownSpec) dropdownCode: string,
  ): Promise<BaseResponses<CalistaDropdown>> {
    this.selfService.buildBaseFilter(offset, limit, sort, where);
    await this.selfService.buildSearchQuery(q);
    return this.selfService.find({ dropdownCode });
  }
}