member_webapp/@overflow/notification/store/detail/notification.effect.ts
crusader d59d9379f9 ing
2018-05-24 15:44:13 +09:00

51 lines
1.3 KiB
TypeScript

import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/exhaustMap';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
import { RPCClientError } from '@loafer/ng-rpc';
import { Notification } from '@overflow/commons-typescript/model/notification';
import { NotificationService } from '../../service/notification.service';
import {
MarkAsRead,
MarkAsReadSuccess,
MarkAsReadFailure,
ActionType,
} from './notification.action';
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private notificationService: NotificationService,
private router: Router
) { }
@Effect()
markAsRead$: Observable<Action> = this.actions$
.ofType(ActionType.MarkAsRead)
.map((action: MarkAsRead) => action.payload)
.switchMap(payload => this.notificationService.markAsRead(payload))
.map(notification => {
return new MarkAsReadSuccess(notification);
})
.catch((error: RPCClientError) => {
console.log(error.response.message);
return of(new MarkAsReadFailure(error));
});
}