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 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | 1x 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, del, get, getWhereSchemaFor, oas, param } from '@loopback/rest';
import { EnsurePagingCorrectInterceptor, serialize } from '@logchain/interceptors';
import { BaseController, MixinOptions, BaseFlowControllerMixin } from '@logchain/controllers';
import { buildResponseObject, buildResponseObjectById, limitSpec, offsetSpec, qSpec, sortSpec, } from '@logchain/apidefs';
import { Module, Constants, CONTENT_TYPE } from '@logchain/configs';
import { FlowDefaultDto } from '@logchain/dtos';
import { BaseResponses, FlowDefault } from '@logchain/models';
import { FlowDefaultService } from '@logchain/services';
const options: MixinOptions = {
basePath: '/flows-default',
modelClass: FlowDefault,
modelDtoClass: FlowDefaultDto,
admin: true,
schemaOptions: {
upsertFlow: {
title: 'NewFlowDefault1',
exclude: [
'stats',
'step',
'flow_default_id',
'created_date',
'created_by',
'modified_date',
'modified_by',
],
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Create, Constants.AccessScope.Update],
},
},
upsertStep: {
title: 'NewStep',
exclude: [
'flow_default_id',
'created_date',
'created_by',
'modified_date',
'modified_by',
'delete',
],
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Create, Constants.AccessScope.Update],
},
},
upsertGroup: {
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Create, Constants.AccessScope.Update],
},
},
upsertPersona: {
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Create, Constants.AccessScope.Update],
},
},
upsertStepDetails: {
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Create, Constants.AccessScope.Update],
},
},
findById: {
exclude: [],
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
find: {
exclude: [],
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Retrieve],
},
},
deleteById: {
authorize: {
resource: Module.LogChain.FlowMgmt,
scopes: [Constants.AccessScope.Delete],
},
},
},
};
@oas.tags('Flow Default')
@api({ basePath: '/admin' })
@authenticate('aws-cognito')
export class FlowDefaultPrivateController extends BaseFlowControllerMixin<
FlowDefault,
Constructor<BaseController>
>(BaseController, options) {
constructor(
@service(FlowDefaultService)
public selfService: FlowDefaultService,
) {
super();
}
/**
* Get model instance by id
* @param id The ID of model
* @returns Model instance
*/
@get(`/${options.basePath}/{id}`, {
responses: {
'200': {
description: `${options.modelClass.modelName} model instance`,
content: {
[CONTENT_TYPE.JSON]: {
schema: buildResponseObjectById(
options.modelDtoClass,
options.admin,
),
},
},
},
},
})
@authorize(options.schemaOptions['findById'].authorize)
@intercept(serialize(FlowDefaultDto))
async findById(
@param.path.integer('id') id: number,
@param.query.integer('step') step: number,
@param.query.integer('step_id') step_id: number,
@param.query.integer('group_id') group_id: number,
@param.query.boolean('r_journey') r_journey: boolean,
) {
return this.selfService.getByIdOrIdentifier(id, {
is_private: this.is_private,
step,
step_id,
group_id,
r_journey,
});
}
/**
* Delete flow by id
* @param id The flow id
* @returns Promise<void>
*/
@del(`/${options.basePath}/{id}`, {
responses: {
'204': {
description: `Default flow DELETE success`,
},
},
})
@authorize(options.schemaOptions['deleteById'].authorize)
async deleteById(@param.path.integer('id') id: number): Promise<void> {
const deleted_inst = await this.selfService.deleteByIdOrIdentifier(id, {
is_private: this.is_private,
});
const action = deleted_inst?.activity?.args?.length ? deleted_inst?.activity.args[0] as string : undefined;
this.writeLog(options.modelClass, id, deleted_inst, deleted_inst.activity, action);
}
/**
* Find list of default flow 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(FlowDefaultDto))
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<FlowDefault>,
): Promise<BaseResponses<FlowDefault>> {
this.selfService.buildBaseFilter(offset, limit, sort, where);
await this.selfService.buildSearchQuery(q);
return this.selfService.find({ is_private: this.is_private });
}
}
|