ActionsController.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { Request, Response } from 'express'
  2. import { inject } from 'inversify'
  3. import { BaseHttpController, controller, httpGet, httpPost } from 'inversify-express-utils'
  4. import { TYPES } from '../../Bootstrap/Types'
  5. import { ServiceProxyInterface } from '../../Service/Proxy/ServiceProxyInterface'
  6. import { EndpointResolverInterface } from '../../Service/Resolver/EndpointResolverInterface'
  7. @controller('/v1')
  8. export class ActionsController extends BaseHttpController {
  9. constructor(
  10. @inject(TYPES.ApiGateway_ServiceProxy) private serviceProxy: ServiceProxyInterface,
  11. @inject(TYPES.ApiGateway_EndpointResolver) private endpointResolver: EndpointResolverInterface,
  12. ) {
  13. super()
  14. }
  15. @httpPost('/login')
  16. async login(request: Request, response: Response): Promise<void> {
  17. await this.serviceProxy.callAuthServer(
  18. request,
  19. response,
  20. this.endpointResolver.resolveEndpointOrMethodIdentifier('POST', 'auth/sign_in'),
  21. request.body,
  22. )
  23. }
  24. @httpGet('/login-params', TYPES.ApiGateway_OptionalCrossServiceTokenMiddleware)
  25. async loginParams(request: Request, response: Response): Promise<void> {
  26. await this.serviceProxy.callAuthServer(
  27. request,
  28. response,
  29. this.endpointResolver.resolveEndpointOrMethodIdentifier('GET', 'auth/params'),
  30. request.body,
  31. )
  32. }
  33. @httpPost('/logout', TYPES.ApiGateway_OptionalCrossServiceTokenMiddleware)
  34. async logout(request: Request, response: Response): Promise<void> {
  35. await this.serviceProxy.callAuthServer(
  36. request,
  37. response,
  38. this.endpointResolver.resolveEndpointOrMethodIdentifier('POST', 'auth/sign_out'),
  39. request.body,
  40. )
  41. }
  42. @httpGet('/unsubscribe/:token')
  43. async emailUnsubscribe(request: Request, response: Response): Promise<void> {
  44. await this.serviceProxy.callEmailServer(
  45. request,
  46. response,
  47. `subscriptions/actions/unsubscribe/${request.params.token}`,
  48. request.body,
  49. )
  50. }
  51. @httpPost('/recovery/codes', TYPES.ApiGateway_RequiredCrossServiceTokenMiddleware)
  52. async recoveryCodes(request: Request, response: Response): Promise<void> {
  53. await this.serviceProxy.callAuthServer(
  54. request,
  55. response,
  56. this.endpointResolver.resolveEndpointOrMethodIdentifier('POST', 'auth/recovery/codes'),
  57. request.body,
  58. )
  59. }
  60. @httpPost('/recovery/login')
  61. async recoveryLogin(request: Request, response: Response): Promise<void> {
  62. await this.serviceProxy.callAuthServer(
  63. request,
  64. response,
  65. this.endpointResolver.resolveEndpointOrMethodIdentifier('POST', 'auth/recovery/login'),
  66. request.body,
  67. )
  68. }
  69. @httpPost('/recovery/login-params')
  70. async recoveryParams(request: Request, response: Response): Promise<void> {
  71. await this.serviceProxy.callAuthServer(
  72. request,
  73. response,
  74. this.endpointResolver.resolveEndpointOrMethodIdentifier('POST', 'auth/recovery/params'),
  75. request.body,
  76. )
  77. }
  78. }