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 | 1x 1x 1x 1x 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, RequestBodyObject} from '@loopback/rest';
import {createBaseControllerFactory, BaseController, MixinOptions, ExtendOptions} from '@logchain/controllers';
import {PersonaDto} from '@logchain/dtos';
import {Persona} from '@logchain/models';
import {PersonaService} from '@logchain/services';
import {Constants, CONTENT_TYPE, Module} from '@logchain/configs';
const { GetFiltersActionsSchema } = require('@logchain/apidefs/schemas/persona-action.schema');
/**
* Define custom response body
*/
const get_actions_by_personas_schema: RequestBodyObject = {
description: 'The request body for get actions by personas.',
content: {
[CONTENT_TYPE.JSON]: {
schema: GetFiltersActionsSchema(),
},
},
};
const get_actions_by_personas_and_cargo_schema: RequestBodyObject = {
description: 'The request body for get actions by persona and cargo.',
content: {
[CONTENT_TYPE.JSON]: {
schema: GetFiltersActionsSchema(),
},
},
};
/**
* Define the MixinOptions for find
*/
const options: MixinOptions = {
basePath: '/personas',
modelClass: Persona,
modelDtoClass: PersonaDto,
admin: false,
schemaOptions: {
find: {
exclude: ['description', 'created_date', 'created_by', 'modified_date', 'modified_by', 'privacy_status'],
},
getActionsByPersona: {
authorize: {
resource: Module.Admin.TradeLaneMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
jsonSchema: get_actions_by_personas_schema,
},
getActionsByPersonaAndCargo: {
authorize: {
resource: Module.Admin.TradeLaneMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
jsonSchema: get_actions_by_personas_and_cargo_schema,
},
},
};
const extendOptions: ExtendOptions = {
isExtendRead: true,
};
@oas.tags('Persona')
@authenticate('aws-cognito')
export class PersonaController extends createBaseControllerFactory<Persona, Constructor<BaseController>>(
BaseController,
options,
extendOptions,
) {
constructor(
@service(PersonaService)
public selfService: PersonaService,
) {
super();
}
/**
* Find list of filters on trade-land based on query
*/
@get(`${options.basePath}/actions`, {
responses: {
'200': options.schemaOptions['getActionsByPersona'].jsonSchema,
},
})
async getActionsByPersona() {
this.selfService.ensureRightAccessRecord();
return this.selfService.getActionsByPersona();
}
/**
* Find list of filters on trade-land based on query
*/
@get(`${options.basePath}/actions/{cargo_type}`, {
responses: {
'200': options.schemaOptions['getActionsByPersonaAndCargo'].jsonSchema,
},
})
async getActionsByPersonaAndCargo(@param.path.integer('cargo_type') cargo_type: number,) {
this.selfService.ensureRightAccessRecord();
return this.selfService.getActionsByPersonaAndCargo(cargo_type);
}
}
|