mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
#929 Take1 on updateShippingDocument 2 update remi process in store once
This commit is contained in:
@@ -10,7 +10,16 @@ import {
|
||||
SetRemissionProcess,
|
||||
SetRemissionShippingDocument,
|
||||
} from '../actions/remission.actions';
|
||||
import { flatMap, filter, map, catchError, switchMap, first, withLatestFrom } from 'rxjs/operators';
|
||||
import {
|
||||
flatMap,
|
||||
filter,
|
||||
map,
|
||||
catchError,
|
||||
switchMap,
|
||||
first,
|
||||
withLatestFrom,
|
||||
take,
|
||||
} from 'rxjs/operators';
|
||||
import { RemissionService, RemissionProcess } from '@isa/remission';
|
||||
import { of } from 'rxjs';
|
||||
import { ResetBreadcrumbsTo } from '../actions/breadcrumb.actions';
|
||||
@@ -19,7 +28,12 @@ import { Router } from '@angular/router';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class RemissionStateHandler {
|
||||
constructor(private actions$: Actions, private store: Store, private remissionService: RemissionService, private router: Router) {
|
||||
constructor(
|
||||
private actions$: Actions,
|
||||
private store: Store,
|
||||
private remissionService: RemissionService,
|
||||
private router: Router
|
||||
) {
|
||||
this.registerHandlers();
|
||||
}
|
||||
|
||||
@@ -34,16 +48,22 @@ export class RemissionStateHandler {
|
||||
.pipe(ofActionDispatched(UpdateShippingDocuent))
|
||||
.pipe(
|
||||
switchMap((action: UpdateShippingDocuent) =>
|
||||
this.remissionService.getRemission({
|
||||
remissionProcessId: action.remissionProcessId,
|
||||
})
|
||||
this.remissionService
|
||||
.getRemission({
|
||||
remissionProcessId: action.remissionProcessId,
|
||||
})
|
||||
.pipe(take(1))
|
||||
)
|
||||
)
|
||||
.subscribe((process) => {
|
||||
const activeShippingDocument = process.shippingDocuments.find((document) => !document.isCompleted);
|
||||
const activeShippingDocument = process.shippingDocuments.find(
|
||||
(document) => !document.isCompleted
|
||||
);
|
||||
|
||||
if (activeShippingDocument) {
|
||||
this.store.dispatch(new SetRemissionShippingDocument(activeShippingDocument));
|
||||
this.store.dispatch(
|
||||
new SetRemissionShippingDocument(activeShippingDocument)
|
||||
);
|
||||
}
|
||||
|
||||
return this.store.dispatch(new SetRemissionProcess(process));
|
||||
@@ -75,7 +95,9 @@ export class RemissionStateHandler {
|
||||
})
|
||||
)
|
||||
.subscribe(([result, process]) => {
|
||||
this.store.dispatch(new SetRemissionFilter(result.remissionProcessId, result.filter));
|
||||
this.store.dispatch(
|
||||
new SetRemissionFilter(result.remissionProcessId, result.filter)
|
||||
);
|
||||
this.store.dispatch(new SetRemissionProcess(process));
|
||||
});
|
||||
}
|
||||
@@ -85,16 +107,24 @@ export class RemissionStateHandler {
|
||||
.pipe(ofActionDispatched(RequestDeleteShippingDocument))
|
||||
.pipe(
|
||||
map((action: RequestDeleteShippingDocument) => action.remissionProcess),
|
||||
filter((action) => !!action.shippingDocuments && !!action.shippingDocuments[0]),
|
||||
filter(
|
||||
(action) =>
|
||||
!!action.shippingDocuments && !!action.shippingDocuments[0]
|
||||
),
|
||||
flatMap((action: RemissionProcess) =>
|
||||
this.remissionService
|
||||
.deleteShippingDocument({
|
||||
remissionProcessId: action.id,
|
||||
externalId: action.externalId,
|
||||
shippingDocumentId: action.shippingDocuments && action.shippingDocuments[0] && action.shippingDocuments[0].id,
|
||||
shippingDocumentId:
|
||||
action.shippingDocuments &&
|
||||
action.shippingDocuments[0] &&
|
||||
action.shippingDocuments[0].id,
|
||||
})
|
||||
.pipe(
|
||||
filter((response) => !!response.result && response.result.deleted),
|
||||
filter(
|
||||
(response) => !!response.result && response.result.deleted
|
||||
),
|
||||
map((_) => action.id),
|
||||
catchError((err) => {
|
||||
console.error(err);
|
||||
@@ -105,7 +135,9 @@ export class RemissionStateHandler {
|
||||
)
|
||||
)
|
||||
.subscribe((remissionProcessId) => {
|
||||
this.store.dispatch(new DeleteRemissionShippingDocument(remissionProcessId));
|
||||
this.store.dispatch(
|
||||
new DeleteRemissionShippingDocument(remissionProcessId)
|
||||
);
|
||||
this.store.dispatch(new ResetRemissionState());
|
||||
this.navigateToStartPage();
|
||||
});
|
||||
@@ -124,6 +156,10 @@ export class RemissionStateHandler {
|
||||
)
|
||||
);
|
||||
|
||||
this.router.navigate([path]).then((_) => this.store.dispatch(new SetBranchProcessCurrentPath(path, true)));
|
||||
this.router
|
||||
.navigate([path])
|
||||
.then((_) =>
|
||||
this.store.dispatch(new SetBranchProcessCurrentPath(path, true))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user