summaryrefslogtreecommitdiff
path: root/src/api/sagas/simulations.js
blob: 9c3bd24c6a78989b858bf533a8ac89de59202ff7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import {call, put} from "redux-saga/effects";
import {addToAuthorizationStore, addToSimulationStore} from "../../actions/objects";
import {addSimulationSucceeded, deleteSimulationSucceeded} from "../../actions/simulations";
import {addSimulation, deleteSimulation} from "../routes/simulations";

export function* onSimulationAdd(action) {
    try {
        const simulation = yield call(addSimulation, {name: action.name});
        yield put(addToSimulationStore(simulation));

        const authorization = {
            simulationId: simulation.id,
            userId: action.userId,
            authorizationLevel: "OWN"
        };
        yield put(addToAuthorizationStore(authorization));
        yield put(addSimulationSucceeded([authorization.userId, authorization.simulationId]));
    } catch (error) {
        console.log(error);
    }
}

export function* onSimulationDelete(action) {
    try {
        yield call(deleteSimulation, action.id);
        yield put(deleteSimulationSucceeded(action.id));
    } catch (error) {
        console.log(error);
    }
}