Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { select, Store } from '@ngrx/store';
  3.  
  4. import { Observable } from 'rxjs';
  5.  
  6. import { ErrorDto } from '@models/error';
  7.  
  8. import {
  9. Auth,
  10. CreateLoginDto,
  11. LoginDto,
  12. SendNewActivationTokenDto,
  13. TokenDto
  14. } from '@models/auth';
  15.  
  16. import { State } from '../reducers';
  17. import {
  18. selectAccount,
  19. selectError,
  20. selectIsAuthenticated,
  21. selectLoading,
  22. selectRegistered,
  23. selectToken
  24. } from '../selectors';
  25.  
  26. import * as AuthActions from '../actions';
  27.  
  28. @Injectable()
  29. export class AuthFacade {
  30. get account$(): Observable<Auth | null> {
  31. return this.store.pipe(select(selectAccount));
  32. }
  33.  
  34. get error$(): Observable<ErrorDto | null> {
  35. return this.store.pipe(select(selectError));
  36. }
  37.  
  38. get isAuthenticated$() {
  39. return this.store.pipe(select(selectIsAuthenticated));
  40. }
  41.  
  42. get loading$(): Observable<boolean> {
  43. return this.store.pipe(select(selectLoading));
  44. }
  45.  
  46. get registered$(): Observable<boolean> {
  47. return this.store.pipe(select(selectRegistered));
  48. }
  49.  
  50. get token$(): Observable<TokenDto | null> {
  51. return this.store.pipe(select(selectToken));
  52. }
  53.  
  54. constructor(private store: Store<State>) {}
  55.  
  56. activateUser(token: string): void {
  57. this.store.dispatch(AuthActions.activateUser({ token }));
  58. }
  59.  
  60. logged(): void {
  61. this.store.dispatch(AuthActions.logged());
  62. }
  63.  
  64. login(credentials: LoginDto): void {
  65. this.store.dispatch(AuthActions.login({ credentials }));
  66. }
  67.  
  68. logout(): void {
  69. this.store.dispatch(AuthActions.logout());
  70. }
  71.  
  72. sendNewActivationToken(payload: SendNewActivationTokenDto): void {
  73. this.store.dispatch(AuthActions.newActivationToken({ payload }));
  74. }
  75.  
  76. notActivationSent(): void {
  77. this.store.dispatch(AuthActions.notActivationSent());
  78. }
  79.  
  80. reset(): void {
  81. this.store.dispatch(AuthActions.loginReset());
  82. }
  83.  
  84. signup(account: CreateLoginDto): void {
  85. this.store.dispatch(AuthActions.signup({ account }));
  86. }
  87.  
  88. signedUp(): void {
  89. this.store.dispatch(AuthActions.signedUp());
  90. }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement