Created
July 27, 2021 13:50
-
-
Save jsCommander/3ea7b352c31a6c4c3b72ba2e654ecb8e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
initPatient$ = createEffect(() => | |
this.actions$.pipe( | |
ofType(ROUTER_NAVIGATION), | |
filter( | |
(action: RouterNavigationAction) => | |
new URL( | |
window.location.protocol + window.location.hostname + action.payload.routerState.url | |
).pathname === '/patients/search' | |
), | |
mergeMap((action: RouterNavigationAction) => | |
this.store.pipe( | |
select(lastNavigatedUrlFeatureKey), | |
filter((lastNavigatedUrl) => { | |
return !lastNavigatedUrl.includes( | |
new URL( | |
window.location.protocol + | |
window.location.hostname + | |
action.payload.routerState.url | |
).pathname | |
); | |
}), | |
first(), | |
mergeMap(() => | |
this.store.pipe( | |
select('router'), | |
first(), | |
mergeMap((router) => | |
this.store.pipe( | |
select(checkCaseColumnsExistsSelector), | |
filter((val) => val !== null), | |
first(), | |
mergeMap(() => | |
this.store.pipe( | |
select(allowToInitPatientsSelector), | |
filter((val) => val), | |
first(), | |
mergeMap((caseColumnsExists) => | |
this.store.pipe( | |
select(configFeatureKey), | |
filter((val) => Boolean(val)), | |
first(), | |
tap(() => | |
this.store.dispatch(incrementPendingOperationCount()) | |
), | |
mergeMapTo( | |
new Observable<GetByKpiResponse>( | |
(subscriber: Subscriber<GetByKpiResponse>) => { | |
this.patientsService | |
.getPatientsByKpi({ | |
Offset: router.state.root.queryParams | |
.page | |
? '' + | |
(router.state.root.queryParams | |
.page - | |
1) | |
: '0', | |
Limit: router.state.root.queryParams | |
.pageSize | |
? '' + | |
router.state.root.queryParams | |
.pageSize | |
: this.DEFAULT_PAGE_SIZE, | |
'sort-field': 'fullName', | |
'sort-direction': '1', | |
}) | |
.then((res: GetByKpiResponse) => { | |
if ( | |
+router.state.root.queryParams | |
?.page | |
) { | |
if ( | |
router.state.root.queryParams | |
?.page === '1' | |
) { | |
this.router.navigate( | |
['/patients/search'], | |
{ | |
relativeTo: this | |
.route, | |
queryParams: { | |
page: null, | |
}, | |
} | |
); | |
} | |
this.store.dispatch( | |
setPage({ | |
page: | |
+router.state.root | |
.queryParams | |
.page - 1, | |
}) | |
); | |
} | |
if ( | |
router.state.root.queryParams | |
?.pageSize | |
) { | |
this.store.dispatch( | |
setPageSize({ | |
pageSize: +router.state | |
.root.queryParams | |
.pageSize, | |
}) | |
); | |
} | |
subscriber.next(res); | |
subscriber.complete(); | |
}) | |
.catch((err) => subscriber.error(err)); | |
} | |
).pipe( | |
catchError((err) => { | |
console.error(err); | |
this.store.dispatch( | |
decrementPendingOperationCount() | |
); | |
this.store.dispatch( | |
setDirectories({ directories: {} }) | |
); | |
return of(null); | |
}) | |
) | |
), | |
map((res) => | |
res | |
? patientsLoaded({ | |
patients: denormalizePatients(res?.pd), | |
total: res?.length, | |
preservePage: true, | |
}) | |
: patientsLoadError({ | |
error: 'Ошибка при загрузке пациентов.', | |
}) | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment