UNPKG

@modyo/cli

Version:

Modyo Command Line Interface

88 lines (80 loc) 2.42 kB
/* eslint no-param-reassign: ["error", {"ignorePropertyModificationsFor": ["state"] }] */ import Vuex from 'vuex'; import axios from 'axios'; export default new Vuex.Store({ state: { accounts: [], cards: [], paramClientId: 1, advanceAmount: 0, monthlyAmount: 0, rate: 0, cae: 0, }, mutations: { SET_ACCOUNTS(state, data) { state.accounts = data; }, SET_CARDS(state, data) { state.cards = data; }, SET_PARAM_CLIENT_ID(state, data) { state.paramClientId = data; }, SET_ADVANCE_AMOUNT(state, data) { state.advanceAmount = data; }, SET_MONTHLY_AMOUNT(state, data) { state.monthlyAmount = data; }, SET_RATE(state, data) { state.rate = data; }, SET_CAE(state, data) { state.cae = data; }, }, actions: { DO_DATA_INITIALIZATION(context) { return new Promise(((resolve, reject) => { context.dispatch('GET_ACCOUNTS') .then(() => { context.dispatch('GET_CARDS') .then((cards) => { resolve(cards); }) .catch(error => reject(error)); }) .catch(error => reject(error)); })); }, GET_ACCOUNTS(context) { context.commit('SET_ACCOUNTS', []); return axios.get(`https://api-bank.herokuapp.com/api/v1/clients/${context.state.paramClientId}/accounts`) .then((response) => { context.commit('SET_ACCOUNTS', response.data); return response; }, err => err); }, GET_ADVANCE_DATA(context, payload) { return axios.post('https://api-bank.herokuapp.com/api/v1/creditCards/cash-advance', payload) .then((response) => { context.commit('SET_ADVANCE_AMOUNT', response.data.advanceAmount); context.commit('SET_MONTHLY_AMOUNT', response.data.monthlyAmount); context.commit('SET_RATE', response.data.rate); context.commit('SET_CAE', response.data.cae); return response; }) .catch(error => error); }, GET_CARDS(context) { context.commit('SET_CARDS', []); return axios.get(`https://api-bank.herokuapp.com/api/v1/clients/${context.state.paramClientId}/creditCards`) .then((response) => { context.commit('SET_CARDS', response.data); return response; }) .catch(err => err); }, }, });