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

66.67% Statements 18/27
100% Branches 0/0
0% Functions 0/3
64% Lines 16/25

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 1201x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x     1x                                       1x           1x                                                                     1x                                                           1x                            
import { authorize } from '@loopback/authorization';
import { intercept, service, Constructor } from '@loopback/core';
import { put, requestBody, oas, get, param, getWhereSchemaFor } from '@loopback/rest';
import { authenticate } from '@loopback/authentication';
 
import { BaseController, MixinOptions, createBaseControllerFactory, ExtendOptions } from '@logchain/controllers';
import { serialize, EnsurePagingCorrectInterceptor } from '@logchain/interceptors';
import { CompanyRegulatory, BaseResponses, CompanyRegulatoryHistories } from '@logchain/models';
import { CompanyRegulatoryHistoriesService, CompanyRegulatoryService } from '@logchain/services';
import { Module, Constants, CONTENT_TYPE } from '@logchain/configs';
import { CompanyRegulatoryDto, CompanyRegulatoryHistoriesDto } from '@logchain/dtos';
import { buildResponseObject, offsetSpec, limitSpec, sortSpec, qSpec } from '@logchain/apidefs';
import { Where } from '@loopback/repository';
 
const options: MixinOptions = {
  basePath: '/companies-regulatory',
  modelClass: CompanyRegulatory,
  modelDtoClass: CompanyRegulatoryDto,
  schemaOptions: {
    find: {
      authorize: {
        resource: Module.Admin.CompanyMgmt,
        scopes: [Constants.AccessScope.Retrieve],
      },
    },
    findRegulatoryHistories: {
      authorize: {
        resource: Module.Admin.CompanyMgmt,
        scopes: [Constants.AccessScope.Retrieve],
      },
    }
  },
};
 
const extendOptions: ExtendOptions = {
  isExtendRead: true,
}
 
@oas.tags('Company Regulatory')
@authenticate('aws-cognito')
export class CompanyRegulatoryController extends createBaseControllerFactory<CompanyRegulatory, Constructor<BaseController>>(BaseController, options, extendOptions) {
  constructor(
    @service(CompanyRegulatoryService)
    public selfService: CompanyRegulatoryService,
    @service(CompanyRegulatoryHistoriesService)
    public companyRegulatoryHistoriesService: CompanyRegulatoryHistoriesService
  ) {
    super();
  }
 
  @put(`${options.basePath}`, {
    responses: {
      '200': {
        description: 'The ID of the new Regulatory',
        content: {
          [CONTENT_TYPE.JSON]: {
            schema: {
              type: 'object',
              properties: {
                id: { type: 'number', },
              },
            },
          },
        },
      },
      '204': {
        description: 'The Regulatory PUT success',
      },
    },
  })
  @intercept(serialize(CompanyRegulatoryDto))
  @authorize({
    resource: Module.Admin.CompanyMgmt,
    scopes: [Constants.AccessScope.Update],
  })
  async upsertRegulatory(
    @requestBody({
      content: {
        [CONTENT_TYPE.JSON]: {
          schema: {
            type: 'object',
            additionalProperties: false,
            required: ["uen", "tradeweb_id"],
            properties: {
              uen: { type: 'string' },
              tradeweb_id: { type: 'string' },
            },
          },
        },
      },
    })
    data: CompanyRegulatory,
  ) {
    const { id } = await this.selfService.upsert(data);
    return this.selfService.findCompanyRegulatoryById(id);
  }
 
  @get(`${options.basePath}-histories`, {
    responses: {
      '200': buildResponseObject(options.modelDtoClass, options.admin),
    },
  })
  @intercept(EnsurePagingCorrectInterceptor.BINDING_KEY)
  @authorize(options.schemaOptions['findRegulatoryHistories'].authorize)
  @intercept(serialize(CompanyRegulatoryHistoriesDto))
  async findRegulatoryHistories(
    @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<CompanyRegulatoryHistories>,
  ): Promise<BaseResponses<CompanyRegulatoryHistories>> {
    this.companyRegulatoryHistoriesService.buildBaseFilter(offset, limit, sort, where);
    await this.companyRegulatoryHistoriesService.buildSearchQuery(q);
    this.companyRegulatoryHistoriesService.ensureRightAccessRecord();
    return this.companyRegulatoryHistoriesService.findCompanyRegulatoryHistories();
  }
}