Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. import {inject} from '@loopback/context';
  2. import {
  3. FindRoute,
  4. InvokeMethod,
  5. ParseParams,
  6. Reject,
  7. RequestContext,
  8. RestBindings,
  9. Send,
  10. SequenceHandler,
  11. } from '@loopback/rest';
  12. import {AuthenticationBindings, AuthenticateFn} from '@loopback/authentication';
  13.  
  14. const SequenceActions = RestBindings.SequenceActions;
  15.  
  16. export class MySequence implements SequenceHandler {
  17. constructor(
  18. @inject(SequenceActions.FIND_ROUTE) protected findRoute: FindRoute,
  19. @inject(SequenceActions.PARSE_PARAMS) protected parseParams: ParseParams,
  20. @inject(SequenceActions.INVOKE_METHOD) protected invoke: InvokeMethod,
  21. @inject(SequenceActions.SEND) public send: Send,
  22. @inject(SequenceActions.REJECT) public reject: Reject,
  23. // inject AUTH_ACTION
  24. @inject(AuthenticationBindings.AUTH_ACTION) private authenticateRequest: AuthenticateFn,
  25. ) {}
  26.  
  27. async handle(context: RequestContext) {
  28. try {
  29. const {request, response} = context;
  30. const route = this.findRoute(request);
  31. // call authenticateFn
  32. await this.authenticateRequest(request);
  33. const args = await this.parseParams(request, route);
  34. const result = await this.invoke(route, args);
  35. this.send(response, result);
  36. } catch (err) {
  37. this.reject(context, err);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement