67 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-05-24 15:44:13 +09:00
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { Effect, Actions, ofType } from '@ngrx/effects';
import { Action } from '@ngrx/store';
2018-06-04 17:55:47 +09:00
import { of } from 'rxjs';
import { catchError, exhaustMap, map, tap } from 'rxjs/operators';
2018-05-24 15:44:13 +09:00
import { RPCClientError } from '@loafer/ng-rpc';
2018-05-25 12:31:08 +09:00
import { Domain } from '@overflow/commons-typescript/model/domain';
2018-05-24 15:44:13 +09:00
import {
ReadAllByMember,
ReadAllByMemberSuccess,
ReadAllByMemberFailure,
MarkAllAsRead,
MarkAllAsReadSuccess,
MarkAllAsReadFailure,
2018-05-25 12:31:08 +09:00
ActionType,
2018-05-24 15:44:13 +09:00
} from './notification.action';
2018-05-27 18:12:20 +09:00
import { NotificationService } from '../../../service/notification.service';
2018-05-24 15:44:13 +09:00
@Injectable()
export class Effects {
constructor(
private actions$: Actions,
private notificationService: NotificationService,
private router: Router
) { }
2018-05-25 12:31:08 +09:00
@Effect()
2018-06-04 17:55:47 +09:00
readAllByMember$ = this.actions$.pipe(
ofType(ActionType.ReadAllByMember),
map((action: ReadAllByMember) => action.payload),
exhaustMap(payload =>
this.notificationService
2018-06-06 00:51:49 +09:00
.readAllByMemberEmail(payload.member.email, payload.pageParams)
2018-06-04 17:55:47 +09:00
.pipe(
map(page => {
return new ReadAllByMemberSuccess(page);
}),
catchError(error => of(new ReadAllByMemberFailure(error)))
)
)
);
2018-05-25 12:31:08 +09:00
2018-05-25 12:39:43 +09:00
@Effect()
2018-06-04 17:55:47 +09:00
markAllAsRead$ = this.actions$.pipe(
ofType(ActionType.MarkAllAsRead),
map((action: MarkAllAsRead) => action.payload),
exhaustMap(payload =>
this.notificationService
2018-06-06 00:51:49 +09:00
.markAllAsReadByMemberEmail(payload.member.email, payload.pageParams)
2018-06-04 17:55:47 +09:00
.pipe(
map(page => {
return new MarkAllAsReadSuccess(page);
}),
catchError(error => of(new MarkAllAsReadFailure(error)))
)
)
);
2018-05-24 15:44:13 +09:00
}