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 | 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 } from '@loopback/rest';
import { EnsurePagingCorrectInterceptor, serialize } from '@logchain/interceptors';
import { BaseController, createBaseControllerFactory, ExtendOptions, MixinOptions } from '@logchain/controllers';
import { CategoryDto } from '@logchain/dtos';
import { Category, BaseResponses } from '@logchain/models';
import { CategoryService } 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 { CategoryView } from '@logchain/models/views';
const options: MixinOptions = {
basePath: '/categories',
modelClass: Category,
modelDtoClass: CategoryDto,
admin: false,
schemaOptions: {
find: {
exclude: [
'created_by',
'modified_by',
'created_date',
'modified_date',
],
authorize: {
resource: Module.Admin.CategoryMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
findById: {
exclude: [
'created_by',
'modified_by',
'created_date',
'modified_date',
],
authorize: {
resource: Module.Admin.CategoryMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
findAvailable: {
exclude: [
'type_detail',
'description',
'user_count',
'created_by',
'modified_by',
'created_date',
'modified_date',
],
authorize: {
resource: Module.Admin.CategoryMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
},
};
const extendOptions: ExtendOptions = {
isExtendRead: true,
isExtendReadById: true,
}
/**
* Category controller
*/
@oas.tags('Category')
@authenticate('aws-cognito')
@intercept(serialize(CategoryDto))
export class CategoryController extends createBaseControllerFactory<Category, Constructor<BaseController>>(BaseController, options, extendOptions) {
constructor(
@service(CategoryService)
public selfService: CategoryService,
) {
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(CategoryDto))
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<Category>,
): Promise<BaseResponses<CategoryView>> {
this.selfService.buildBaseFilter(offset, limit, sort, where);
await this.selfService.buildSearchQuery(q);
this.selfService.ensureRightAccessRecord();
this.selfService.ensureUserRightAccessRecord();
return this.selfService.find();
}
/**
* Find list of categories based on flow id
* @param flow_id The flow id
* @param offset The offset number
* @param limit The limit number
* @param sort The array order
* @param where The query object
*/
@get(`${options.basePath}/{flow_id}/available`, {
responses: {
'200': buildResponseObject(options.modelDtoClass, options.admin),
},
})
@intercept(EnsurePagingCorrectInterceptor.BINDING_KEY)
@authorize(options.schemaOptions['findAvailable'].authorize)
@intercept(serialize(CategoryDto))
async getAvailable(
@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<Category>,
@param.path.integer('flow_id') flow_id: number,
): Promise<BaseResponses<CategoryView>> {
this.selfService.buildBaseFilter(offset, limit, sort, where);
await this.selfService.buildSearchQuery(q);
this.selfService.ensureRightAccessRecord();
return this.selfService.getAvailable(flow_id);
}
}
|