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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { authenticate } from '@loopback/authentication';
import { authorize } from '@loopback/authorization';
import { Constructor, intercept, service } from '@loopback/core';
import { Where } from '@loopback/repository';
import { api, get, getWhereSchemaFor, oas, param } from '@loopback/rest';
import { EnsurePagingCorrectInterceptor, serialize } from '@logchain/interceptors';
import { BaseController, MixinOptions, createBaseControllerFactory, ExtendOptions } from '@logchain/controllers';
import { buildResponseObject, limitSpec, offsetSpec, qSpec, sortSpec, } from '@logchain/apidefs';
import { Module, Constants } from '@logchain/configs';
import { ModuleDto, RoleDto } from '@logchain/dtos';
import { Feature, Role } from '@logchain/models';
import { RoleService } from '@logchain/services';
/**
* Define the MixinOptions
*/
const options: MixinOptions = {
basePath: '/roles',
modelClass: Role,
modelDtoClass: RoleDto,
admin: true,
schemaOptions: {
create: {
title: 'NewRole2',
exclude: ['user_count', 'user_active'],
authorize: {
resource: Module.LogChain.RoleMgmt,
scopes: [Constants.AccessScope.Create],
},
},
updateById: {
exclude: ['user_count', 'user_active'],
authorize: {
resource: Module.LogChain.RoleMgmt,
scopes: [Constants.AccessScope.Update],
},
},
deleteById: {
exclude: [],
authorize: {
resource: Module.LogChain.RoleMgmt,
scopes: [Constants.AccessScope.Delete],
},
},
findById: {
exclude: [],
authorize: {
resource: Module.LogChain.RoleMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
find: {
exclude: ['access', 'description'],
authorize: {
resource: Module.LogChain.RoleMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
},
};
const extendOptions: ExtendOptions = {
isExtendCreate: true,
isExtendRead: true,
isExtendReadById: true,
isExtendUpdateById: true,
isExtendDeleteById: true,
}
@oas.tags('Role')
@api({ basePath: '/admin' })
@authenticate('aws-cognito')
export class RolePrivateController extends createBaseControllerFactory<Role, Constructor<BaseController>>(BaseController, options, extendOptions) {
constructor(
@service(RoleService)
public selfService: RoleService,
) {
super();
}
/**
* Find list feature for roles
* @param offset The offset number
* @param limit The limit number
* @param sort The array order
* @param where The query object
*/
@get(`${options.basePath}/features`, {
responses: {
'200': buildResponseObject(ModuleDto, false, options.schemaOptions.find),
},
})
@intercept(EnsurePagingCorrectInterceptor.BINDING_KEY)
@intercept(serialize(ModuleDto))
@authorize({
resource: Module.LogChain.RoleMgmt,
scopes: [Constants.AccessScope.Retrieve],
})
async findFeatures(
@param(offsetSpec) offset: number,
@param(limitSpec) limit: number,
@param(sortSpec) sort: Array<string>,
@param(qSpec) q: string,
@param.query.object('where', getWhereSchemaFor(Feature))
where: Where<Feature> = {},
) {
this.selfService.buildBaseFilter(offset, limit, sort, where);
return this.selfService.getFeatures();
}
}
|