UNPKG

@modyo/cli

Version:

Modyo Command Line Interface

50 lines (48 loc) 1.45 kB
/* eslint no-param-reassign: ["error", {"ignorePropertyModificationsFor": ["state"] }] */ import Vuex from 'vuex'; import axios from 'axios'; export default new Vuex.Store({ state: { accounts: [], clientId: 1, }, mutations: { SET_CLIENT_ID(state, data) { state.clientId = data; }, SET_ACCOUNTS(state, data) { state.accounts = data; }, }, actions: { DO_DATA_INITIALIZATION(context) { return new Promise(((resolve, reject) => { context.dispatch('GET_ACCOUNTS').then((accounts) => { resolve(accounts); }) .catch(err => reject(err)); })); }, GET_ACCOUNTS(context) { return axios.get(`https://api-bank.herokuapp.com/api/v1/clients/${context.state.clientId}/accounts`, { params: { 'filter[include]': 'relatedAccount', 'filter[order]': 'accountType', }, }) .then((accounts) => { context.commit('SET_ACCOUNTS', accounts.data); return accounts.data; }, err => err.statusText); }, GET_TRANSACTIONS_FOR_ACCOUNT(context, payload) { const prefix = 'https://api-bank.herokuapp.com/api/v1/clients'; return axios.get(`${prefix}/${context.state.clientId}/accounts/${payload.accountId}/transactions/`, { params: { 'filter[limit]': payload.limit, }, }) .then(transactions => transactions, err => err); }, }, });