53 lines
1.4 KiB
TypeScript
Raw Normal View History

2019-09-25 17:26:19 +09:00
import { Injectable } from '@angular/core';
import { Actions, ofType, createEffect } from '@ngrx/effects';
import { of } from 'rxjs';
import { catchError, exhaustMap, map } from 'rxjs/operators';
import { buddy2, buddy2Success, buddy2Failure, buddy2Data } from './actions';
import { SessionStorageService } from '@ucap-webmessenger/web-storage';
import {
SyncProtocolService,
SSVC_TYPE_SYNC_BUDDY2_DATA,
BuddyResponse,
BuddyDetailData
} from '@ucap-webmessenger/protocol-sync';
import { regViewSuccess } from '@app/store/setting/option';
@Injectable()
export class Effects {
regViewSuccess$ = createEffect(() =>
this.actions$.pipe(
ofType(regViewSuccess),
map(() => buddy2({ syncDate: '' }))
)
);
buddy2$ = createEffect(() =>
this.actions$.pipe(
ofType(buddy2),
exhaustMap(req =>
this.syncProtocolService.buddy2(req).pipe(
map(res => {
switch (res.Type) {
case SSVC_TYPE_SYNC_BUDDY2_DATA:
return buddy2Data({ data: res as BuddyDetailData });
}
return buddy2Success({ res: res as BuddyResponse });
}),
catchError(error => of(buddy2Failure({ error })))
)
)
)
);
constructor(
private actions$: Actions,
private syncProtocolService: SyncProtocolService,
private sessionStorageService: SessionStorageService
) {}
}