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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { authorize } from '@loopback/authorization';
import { authenticate } from '@loopback/authentication';
import { Where } from '@loopback/repository';
import { service, intercept, Constructor } from '@loopback/core';
import { oas, get, param, getWhereSchemaFor, RequestBodyObject, post, requestBody } from '@loopback/rest';
import { EnsurePagingCorrectInterceptor, serialize } from '@logchain/interceptors';
import { BaseController, createBaseControllerFactory, ExtendOptions, MixinOptions } from '@logchain/controllers';
import { CompanyFieldDto } from '@logchain/dtos';
import { CompanyField, BaseResponses } from '@logchain/models';
import { CompanyFieldService } from '@logchain/services';
import { buildResponseObject, offsetSpec, limitSpec, sortSpec, qSpec } from '@logchain/apidefs';
import { Constants } from '@logchain/configs/constants';
import { Module } from '@logchain/configs/module';
import { CONTENT_TYPE } from '@logchain/configs';
/**
* Define custom response body
*/
const create_company_field: RequestBodyObject = {
description: 'The request body for creating a new company field mapping.',
content: {
[CONTENT_TYPE.JSON]: {
schema: {
type: 'object',
properties: {
field_name_db: {
type: 'string',
},
field_name_xml: {
type: 'string',
},
},
},
},
},
};
const options: MixinOptions = {
basePath: '/company/fields',
modelClass: CompanyField,
modelDtoClass: CompanyFieldDto,
admin: false,
schemaOptions: {
find: {
exclude: [
'created_by',
'modified_by',
'created_date',
'modified_date',
],
authorize: {
resource: Module.Admin.TradeLaneMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
create: {
authorize: {
resource: Module.Admin.TradeLaneMgmt,
scopes: [Constants.AccessScope.Create],
},
jsonSchema: create_company_field,
requestBody: create_company_field,
},
deleteById: {
exclude: [],
authorize: {
resource: Module.Admin.TradeLaneMgmt,
scopes: [Constants.AccessScope.Delete],
},
},
},
};
const extendOptions: ExtendOptions = {
isExtendRead: true,
isExtendCreate: true,
isExtendDeleteById: true,
}
/**
* Fields controller
*/
@oas.tags('Company Fields')
@authenticate('aws-cognito')
@intercept(serialize(CompanyFieldDto))
export class CompanyFieldController extends createBaseControllerFactory<CompanyField, Constructor<BaseController>>(BaseController, options, extendOptions) {
constructor(
@service(CompanyFieldService)
public selfService: CompanyFieldService,
) {
super();
}
/**
* Find list of trade land 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}`, {
responses: {
'200': buildResponseObject(options.modelDtoClass, options.admin),
},
})
@intercept(EnsurePagingCorrectInterceptor.BINDING_KEY)
@authorize(options.schemaOptions['find'].authorize)
@intercept(serialize(CompanyFieldDto))
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<CompanyField>,
): Promise<BaseResponses<CompanyField>> {
this.selfService.buildBaseFilter(offset, limit, sort, where);
await this.selfService.buildSearchQuery(q);
this.selfService.ensureRightAccessRecord();
return this.selfService.find();
}
/**
* Create new company field mapping
*/
@post(`/${options.basePath}`, {
responses: {
'200': {
description: 'Create new company field mapping',
},
'400': {
description: 'Validation Errors (Bad Request)',
},
'401': {
description: 'Unauthorized Error',
},
'500': {
description: 'Internal Server Error (System Error)',
},
},
})
@intercept(serialize(CompanyFieldDto))
async create(
@requestBody(options.schemaOptions['create'].requestBody)
payload: CompanyFieldDto,
) {
payload.company_id = this.current_user.company_id;
return this.selfService.create(payload);
}
}
|