| /******************************************************************************** |
| * Copyright (c) 2020 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0 |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ********************************************************************************/ |
| |
| import {Injectable} from "@angular/core"; |
| import {Router} from "@angular/router"; |
| import {Actions, createEffect, ofType} from "@ngrx/effects"; |
| import {Action} from "@ngrx/store"; |
| import {Observable} from "rxjs"; |
| import {exhaustMap, filter, switchMap} from "rxjs/operators"; |
| import {IAPIProcessObject, ProcessApiService} from "../../../core/api/process"; |
| import {completeTaskAction, deleteTaskAction} from "../actions"; |
| |
| @Injectable({providedIn: "root"}) |
| export class CompleteTaskEffect { |
| |
| public readonly completeTask$ = createEffect(() => this.actions$.pipe( |
| ofType(completeTaskAction), |
| filter((action) => typeof action.statementId === "number" && typeof action.taskId === "string"), |
| exhaustMap((action) => this.completeTask(action.statementId, action.taskId, action.variables)) |
| )); |
| |
| public constructor( |
| private readonly actions$: Actions, |
| private readonly processApiService: ProcessApiService, |
| private readonly router: Router |
| ) { |
| |
| } |
| |
| public completeTask(statementId: number, taskId: string, variables: IAPIProcessObject): Observable<Action> { |
| const queryParams = {id: statementId}; |
| return this.processApiService.completeStatementTask(statementId, taskId, variables).pipe( |
| switchMap(async () => { |
| await this.router.navigate(["/details"], {queryParams}); |
| return deleteTaskAction({statementId, taskId}); |
| }) |
| ); |
| } |
| |
| } |