Skip to content

Commit

Permalink
feat(cli): update template for src/sequence.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
raymondfeng committed May 27, 2020
1 parent 35fcbe3 commit 0dadb63
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
46 changes: 2 additions & 44 deletions packages/cli/generators/app/templates/src/sequence.ts.ejs
Original file line number Diff line number Diff line change
@@ -1,45 +1,3 @@
import {inject} from '@loopback/context';
import {
FindRoute,
InvokeMethod,
InvokeMiddleware,
ParseParams,
Reject,
RequestContext,
RestBindings,
Send,
SequenceHandler,
} from '@loopback/rest';
import {MiddlewareSequence} from '@loopback/rest';

const SequenceActions = RestBindings.SequenceActions;

export class MySequence implements SequenceHandler {
/**
* Optional invoker for registered middleware in a chain.
* To be injected via SequenceActions.INVOKE_MIDDLEWARE.
*/
@inject(SequenceActions.INVOKE_MIDDLEWARE, {optional: true})
protected invokeMiddleware: InvokeMiddleware = () => false;

constructor(
@inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
@inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
@inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
@inject(SequenceActions.SEND) public send: Send,
@inject(SequenceActions.REJECT) public reject: Reject,
) {}

async handle(context: RequestContext) {
try {
const {request, response} = context;
const finished = await this.invokeMiddleware(context);
if (finished) return;
const route = this.findRoute(request);
const args = await this.parseParams(request, route);
const result = await this.invoke(route, args);
this.send(response, result);
} catch (err) {
this.reject(context, err);
}
}
}
export class MySequence extends MiddlewareSequence {}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ describe('app-generator specific files', () => {
assertFilesToMatchSnapshot(
{},
'src/application.ts',
'src/sequence.ts',
'src/index.ts',
'src/controllers/ping.controller.ts',
'src/__tests__/acceptance/ping.controller.acceptance.ts',
Expand Down

0 comments on commit 0dadb63

Please sign in to comment.