code refactor
This commit is contained in:
+11
-25
@@ -12,7 +12,7 @@ import {
|
||||
UPDATE_ACCOUNT_LIST_INVALID_STATE
|
||||
} from './mutations.js';
|
||||
|
||||
function loadAllAccounts(context, { force }) {
|
||||
export function loadAllAccounts(context, { force }) {
|
||||
if (!force && !context.state.accountListStateInvalid) {
|
||||
return new Promise((resolve) => {
|
||||
resolve(context.state.allAccounts);
|
||||
@@ -52,7 +52,7 @@ function loadAllAccounts(context, { force }) {
|
||||
});
|
||||
}
|
||||
|
||||
function getAccount(context, { accountId }) {
|
||||
export function getAccount(context, { accountId }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getAccount({
|
||||
id: accountId
|
||||
@@ -79,7 +79,7 @@ function getAccount(context, { accountId }) {
|
||||
});
|
||||
}
|
||||
|
||||
function saveAccount(context, { account }) {
|
||||
export function saveAccount(context, { account }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = null;
|
||||
|
||||
@@ -126,7 +126,7 @@ function saveAccount(context, { account }) {
|
||||
});
|
||||
}
|
||||
|
||||
function changeAccountDisplayOrder(context, { accountId, from, to }) {
|
||||
export function changeAccountDisplayOrder(context, { accountId, from, to }) {
|
||||
const account = context.state.allAccountsMap[accountId];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -149,7 +149,7 @@ function changeAccountDisplayOrder(context, { accountId, from, to }) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateAccountDisplayOrders(context) {
|
||||
export function updateAccountDisplayOrders(context) {
|
||||
const newDisplayOrders = [];
|
||||
|
||||
for (let category in context.state.allCategorizedAccounts) {
|
||||
@@ -195,7 +195,7 @@ function updateAccountDisplayOrders(context) {
|
||||
});
|
||||
}
|
||||
|
||||
function hideAccount(context, { account, hidden }) {
|
||||
export function hideAccount(context, { account, hidden }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.hideAccount({
|
||||
id: account.id,
|
||||
@@ -237,7 +237,7 @@ function hideAccount(context, { account, hidden }) {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteAccount(context, { account, beforeResolve }) {
|
||||
export function deleteAccount(context, { account, beforeResolve }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.deleteAccount({
|
||||
id: account.id
|
||||
@@ -272,7 +272,7 @@ function deleteAccount(context, { account, beforeResolve }) {
|
||||
});
|
||||
}
|
||||
|
||||
function allPlainAccounts(state) {
|
||||
export function allPlainAccounts(state) {
|
||||
const allAccounts = [];
|
||||
|
||||
for (let i = 0; i < state.allAccounts.length; i++) {
|
||||
@@ -291,7 +291,7 @@ function allPlainAccounts(state) {
|
||||
return allAccounts;
|
||||
}
|
||||
|
||||
function allVisiblePlainAccounts(state) {
|
||||
export function allVisiblePlainAccounts(state) {
|
||||
const allVisibleAccounts = [];
|
||||
|
||||
for (let i = 0; i < state.allAccounts.length; i++) {
|
||||
@@ -314,7 +314,7 @@ function allVisiblePlainAccounts(state) {
|
||||
return allVisibleAccounts;
|
||||
}
|
||||
|
||||
function allAvailableAccountsCount(state) {
|
||||
export function allAvailableAccountsCount(state) {
|
||||
let allAccountCount = 0;
|
||||
|
||||
for (let category in state.allCategorizedAccounts) {
|
||||
@@ -328,7 +328,7 @@ function allAvailableAccountsCount(state) {
|
||||
return allAccountCount;
|
||||
}
|
||||
|
||||
function allVisibleAccountsCount(state) {
|
||||
export function allVisibleAccountsCount(state) {
|
||||
let shownAccountCount = 0;
|
||||
|
||||
for (let category in state.allCategorizedAccounts) {
|
||||
@@ -347,17 +347,3 @@ function allVisibleAccountsCount(state) {
|
||||
|
||||
return shownAccountCount;
|
||||
}
|
||||
|
||||
export default {
|
||||
loadAllAccounts,
|
||||
getAccount,
|
||||
saveAccount,
|
||||
changeAccountDisplayOrder,
|
||||
updateAccountDisplayOrders,
|
||||
hideAccount,
|
||||
deleteAccount,
|
||||
allPlainAccounts,
|
||||
allVisiblePlainAccounts,
|
||||
allAvailableAccountsCount,
|
||||
allVisibleAccountsCount,
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
|
||||
const exchangeRatesLocalStorageKey = 'lab_app_exchange_rates';
|
||||
|
||||
function getLatestExchangeRates(context, { silent, force }) {
|
||||
export function getLatestExchangeRates(context, { silent, force }) {
|
||||
const currentExchangeRateData = context.state.latestExchangeRates;
|
||||
const now = new Date();
|
||||
|
||||
@@ -55,12 +55,12 @@ function getLatestExchangeRates(context, { silent, force }) {
|
||||
});
|
||||
}
|
||||
|
||||
function exchangeRatesLastUpdateDate(state) {
|
||||
export function exchangeRatesLastUpdateDate(state) {
|
||||
const exchangeRates = state.latestExchangeRates || {};
|
||||
return exchangeRates && exchangeRates.data ? exchangeRates.data.date : null;
|
||||
}
|
||||
|
||||
function getExchangedAmount(state) {
|
||||
export function getExchangedAmount(state) {
|
||||
return (amount, fromCurrency, toCurrency) => {
|
||||
if (!state.latestExchangeRates || !state.latestExchangeRates.data || !state.latestExchangeRates.data.exchangeRates) {
|
||||
return null;
|
||||
@@ -91,25 +91,16 @@ function getExchangedAmount(state) {
|
||||
};
|
||||
}
|
||||
|
||||
function getExchangeRatesFromLocalStorage() {
|
||||
export function getExchangeRatesFromLocalStorage() {
|
||||
const storageData = localStorage.getItem(exchangeRatesLocalStorageKey) || '{}';
|
||||
return JSON.parse(storageData);
|
||||
}
|
||||
|
||||
function setExchangeRatesToLocalStorage(value) {
|
||||
export function setExchangeRatesToLocalStorage(value) {
|
||||
const storageData = JSON.stringify(value);
|
||||
localStorage.setItem(exchangeRatesLocalStorageKey, storageData);
|
||||
}
|
||||
|
||||
function clearExchangeRatesFromLocalStorage() {
|
||||
export function clearExchangeRatesFromLocalStorage() {
|
||||
localStorage.removeItem(exchangeRatesLocalStorageKey);
|
||||
}
|
||||
|
||||
export default {
|
||||
getLatestExchangeRates,
|
||||
exchangeRatesLastUpdateDate,
|
||||
getExchangedAmount,
|
||||
getExchangeRatesFromLocalStorage,
|
||||
setExchangeRatesToLocalStorage,
|
||||
clearExchangeRatesFromLocalStorage,
|
||||
}
|
||||
|
||||
+161
-73
@@ -40,20 +40,93 @@ import {
|
||||
UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE,
|
||||
} from './mutations.js';
|
||||
|
||||
import user from './user.js';
|
||||
import twoFactorAuth from './twoFactorAuth.js';
|
||||
import token from './token.js';
|
||||
import exchangeRates from './exchangeRates.js';
|
||||
import account from './account.js';
|
||||
import transaction from './transaction.js';
|
||||
import transactionCategory from './transactionCategory.js';
|
||||
import transactionTag from './transactionTag.js';
|
||||
import {
|
||||
authorize,
|
||||
authorize2FA,
|
||||
register,
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
currentUserNickname,
|
||||
currentUserDefaultCurrency,
|
||||
} from './user.js';
|
||||
|
||||
import {
|
||||
get2FAStatus,
|
||||
enable2FA,
|
||||
confirmEnable2FA,
|
||||
disable2FA,
|
||||
regenerate2FARecoveryCode,
|
||||
} from './twoFactorAuth.js';
|
||||
|
||||
import {
|
||||
getAllTokens,
|
||||
refreshTokenAndRevokeOldToken,
|
||||
revokeToken,
|
||||
revokeAllTokens,
|
||||
} from './token.js';
|
||||
|
||||
import {
|
||||
getLatestExchangeRates,
|
||||
exchangeRatesLastUpdateDate,
|
||||
getExchangedAmount,
|
||||
getExchangeRatesFromLocalStorage,
|
||||
setExchangeRatesToLocalStorage,
|
||||
clearExchangeRatesFromLocalStorage,
|
||||
} from './exchangeRates.js';
|
||||
|
||||
import {
|
||||
loadAllAccounts,
|
||||
getAccount,
|
||||
saveAccount,
|
||||
changeAccountDisplayOrder,
|
||||
updateAccountDisplayOrders,
|
||||
hideAccount,
|
||||
deleteAccount,
|
||||
allPlainAccounts,
|
||||
allVisiblePlainAccounts,
|
||||
allAvailableAccountsCount,
|
||||
allVisibleAccountsCount,
|
||||
} from './account.js';
|
||||
|
||||
import {
|
||||
getTransactions,
|
||||
getTransaction,
|
||||
saveTransaction,
|
||||
deleteTransaction,
|
||||
collapseMonthInTransactionList,
|
||||
noTransaction,
|
||||
hasMoreTransaction,
|
||||
calculateMonthTotalAmount,
|
||||
} from './transaction.js';
|
||||
|
||||
import {
|
||||
loadAllCategories,
|
||||
getCategory,
|
||||
saveCategory,
|
||||
addCategories,
|
||||
changeCategoryDisplayOrder,
|
||||
updateCategoryDisplayOrders,
|
||||
hideCategory,
|
||||
deleteCategory,
|
||||
} from './transactionCategory.js';
|
||||
|
||||
import {
|
||||
loadAllTags,
|
||||
saveTag,
|
||||
changeTagDisplayOrder,
|
||||
updateTagDisplayOrders,
|
||||
hideTag,
|
||||
deleteTag,
|
||||
} from './transactionTag.js';
|
||||
|
||||
const stores = {
|
||||
strict: process.env.NODE_ENV !== 'production',
|
||||
state: {
|
||||
currentUserInfo: userState.getUserInfo(),
|
||||
latestExchangeRates: exchangeRates.getExchangeRatesFromLocalStorage(),
|
||||
latestExchangeRates: getExchangeRatesFromLocalStorage(),
|
||||
allAccounts: [],
|
||||
allAccountsMap: {},
|
||||
allCategorizedAccounts: {},
|
||||
@@ -69,16 +142,23 @@ const stores = {
|
||||
transactionTagListStateInvalid: true,
|
||||
},
|
||||
getters: {
|
||||
currentUserNickname: user.currentUserNickname,
|
||||
currentUserDefaultCurrency: user.currentUserDefaultCurrency,
|
||||
exchangeRatesLastUpdateDate: exchangeRates.exchangeRatesLastUpdateDate,
|
||||
getExchangedAmount: exchangeRates.getExchangedAmount,
|
||||
allPlainAccounts: account.allPlainAccounts,
|
||||
allVisiblePlainAccounts: account.allVisiblePlainAccounts,
|
||||
allAvailableAccountsCount: account.allAvailableAccountsCount,
|
||||
allVisibleAccountsCount: account.allVisibleAccountsCount,
|
||||
noTransaction: transaction.noTransaction,
|
||||
hasMoreTransaction: transaction.hasMoreTransaction,
|
||||
// user
|
||||
currentUserNickname,
|
||||
currentUserDefaultCurrency,
|
||||
|
||||
// exchange rates
|
||||
exchangeRatesLastUpdateDate,
|
||||
getExchangedAmount,
|
||||
|
||||
// account
|
||||
allPlainAccounts,
|
||||
allVisiblePlainAccounts,
|
||||
allAvailableAccountsCount,
|
||||
allVisibleAccountsCount,
|
||||
|
||||
// transaction
|
||||
noTransaction,
|
||||
hasMoreTransaction,
|
||||
},
|
||||
mutations: {
|
||||
[RESET_STATE] (state) {
|
||||
@@ -101,7 +181,7 @@ const stores = {
|
||||
state.allTransactionTagsMap = {};
|
||||
state.transactionTagListStateInvalid = true;
|
||||
|
||||
exchangeRates.clearExchangeRatesFromLocalStorage();
|
||||
clearExchangeRatesFromLocalStorage();
|
||||
},
|
||||
[STORE_USER_INFO] (state, userInfo) {
|
||||
state.currentUserInfo = userInfo;
|
||||
@@ -113,7 +193,7 @@ const stores = {
|
||||
},
|
||||
[STORE_LATEST_EXCHANGE_RATES] (state, latestExchangeRates) {
|
||||
state.latestExchangeRates = latestExchangeRates;
|
||||
exchangeRates.setExchangeRatesToLocalStorage(latestExchangeRates);
|
||||
setExchangeRatesToLocalStorage(latestExchangeRates);
|
||||
},
|
||||
[LOAD_ACCOUNT_LIST] (state, accounts) {
|
||||
state.allAccounts = accounts;
|
||||
@@ -296,7 +376,7 @@ const stores = {
|
||||
|
||||
if (currentMonthList && currentMonthList.year === transactionYear && currentMonthList.month === transactionMonth) {
|
||||
currentMonthList.items.push(item);
|
||||
transaction.calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, true);
|
||||
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -306,7 +386,7 @@ const stores = {
|
||||
currentMonthList = state.transactions[j];
|
||||
|
||||
if (j > 0) {
|
||||
transaction.calculateMonthTotalAmount(state, state.transactions[j - 1], defaultCurrency, accountId, false);
|
||||
calculateMonthTotalAmount(state, state.transactions[j - 1], defaultCurrency, accountId, false);
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -314,11 +394,11 @@ const stores = {
|
||||
}
|
||||
|
||||
if (!currentMonthList && state.transactions.length > 0) {
|
||||
transaction.calculateMonthTotalAmount(state, state.transactions[state.transactions.length - 1], defaultCurrency, accountId, false);
|
||||
calculateMonthTotalAmount(state, state.transactions[state.transactions.length - 1], defaultCurrency, accountId, false);
|
||||
}
|
||||
|
||||
if (!currentMonthList || currentMonthList.year !== transactionYear || currentMonthList.month !== transactionMonth) {
|
||||
transaction.calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, false);
|
||||
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, false);
|
||||
|
||||
state.transactions.push({
|
||||
year: transactionYear,
|
||||
@@ -333,14 +413,14 @@ const stores = {
|
||||
}
|
||||
|
||||
currentMonthList.items.push(item);
|
||||
transaction.calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, true);
|
||||
calculateMonthTotalAmount(state, currentMonthList, defaultCurrency, accountId, true);
|
||||
}
|
||||
}
|
||||
|
||||
if (transactions.nextTimeSequenceId) {
|
||||
state.transactionsNextTimeId = transactions.nextTimeSequenceId;
|
||||
} else {
|
||||
transaction.calculateMonthTotalAmount(state, state.transactions[state.transactions.length - 1], defaultCurrency, accountId, false);
|
||||
calculateMonthTotalAmount(state, state.transactions[state.transactions.length - 1], defaultCurrency, accountId, false);
|
||||
state.transactionsNextTimeId = -1;
|
||||
}
|
||||
},
|
||||
@@ -362,7 +442,7 @@ const stores = {
|
||||
for (let j = 0; j < transactionMonthList.items.length; j++) {
|
||||
if (transactionMonthList.items[j].id === transaction.id) {
|
||||
transactionMonthList.items.splice(j, 1, transaction);
|
||||
transaction.calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
|
||||
calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -387,7 +467,7 @@ const stores = {
|
||||
if (transactionMonthList.items.length < 1) {
|
||||
state.transactions.splice(i, 1);
|
||||
} else {
|
||||
transaction.calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
|
||||
calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, i >= state.transactions.length - 1 && state.transactionsNextTimeId > 0);
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -553,57 +633,65 @@ const stores = {
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
authorize: user.authorize,
|
||||
authorize2FA: user.authorize2FA,
|
||||
register: user.register,
|
||||
logout: user.logout,
|
||||
getCurrentUserProfile: user.getCurrentUserProfile,
|
||||
updateUserProfile: user.updateUserProfile,
|
||||
clearUserInfoState: user.clearUserInfoState,
|
||||
resetState: user.resetState,
|
||||
// user
|
||||
authorize,
|
||||
authorize2FA,
|
||||
register,
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
|
||||
get2FAStatus: twoFactorAuth.get2FAStatus,
|
||||
enable2FA: twoFactorAuth.enable2FA,
|
||||
confirmEnable2FA: twoFactorAuth.confirmEnable2FA,
|
||||
disable2FA: twoFactorAuth.disable2FA,
|
||||
regenerate2FARecoveryCode: twoFactorAuth.regenerate2FARecoveryCode,
|
||||
// 2fa
|
||||
get2FAStatus,
|
||||
enable2FA,
|
||||
confirmEnable2FA,
|
||||
disable2FA,
|
||||
regenerate2FARecoveryCode,
|
||||
|
||||
getAllTokens: token.getAllTokens,
|
||||
refreshTokenAndRevokeOldToken: token.refreshTokenAndRevokeOldToken,
|
||||
revokeToken: token.revokeToken,
|
||||
revokeAllTokens: token.revokeAllTokens,
|
||||
// token
|
||||
getAllTokens,
|
||||
refreshTokenAndRevokeOldToken,
|
||||
revokeToken,
|
||||
revokeAllTokens,
|
||||
|
||||
getLatestExchangeRates: exchangeRates.getLatestExchangeRates,
|
||||
// exchange rates
|
||||
getLatestExchangeRates,
|
||||
|
||||
loadAllAccounts: account.loadAllAccounts,
|
||||
saveAccount: account.saveAccount,
|
||||
getAccount: account.getAccount,
|
||||
changeAccountDisplayOrder: account.changeAccountDisplayOrder,
|
||||
updateAccountDisplayOrders: account.updateAccountDisplayOrders,
|
||||
hideAccount: account.hideAccount,
|
||||
deleteAccount: account.deleteAccount,
|
||||
// account
|
||||
loadAllAccounts,
|
||||
saveAccount,
|
||||
getAccount,
|
||||
changeAccountDisplayOrder,
|
||||
updateAccountDisplayOrders,
|
||||
hideAccount,
|
||||
deleteAccount,
|
||||
|
||||
getTransactions: transaction.getTransactions,
|
||||
getTransaction: transaction.getTransaction,
|
||||
saveTransaction: transaction.saveTransaction,
|
||||
deleteTransaction: transaction.deleteTransaction,
|
||||
collapseMonthInTransactionList: transaction.collapseMonthInTransactionList,
|
||||
// transaction
|
||||
getTransactions,
|
||||
getTransaction,
|
||||
saveTransaction,
|
||||
deleteTransaction,
|
||||
collapseMonthInTransactionList,
|
||||
|
||||
loadAllCategories: transactionCategory.loadAllCategories,
|
||||
getCategory: transactionCategory.getCategory,
|
||||
saveCategory: transactionCategory.saveCategory,
|
||||
addCategories: transactionCategory.addCategories,
|
||||
changeCategoryDisplayOrder: transactionCategory.changeCategoryDisplayOrder,
|
||||
updateCategoryDisplayOrders: transactionCategory.updateCategoryDisplayOrders,
|
||||
hideCategory: transactionCategory.hideCategory,
|
||||
deleteCategory: transactionCategory.deleteCategory,
|
||||
// transaction category
|
||||
loadAllCategories,
|
||||
getCategory,
|
||||
saveCategory,
|
||||
addCategories,
|
||||
changeCategoryDisplayOrder,
|
||||
updateCategoryDisplayOrders,
|
||||
hideCategory,
|
||||
deleteCategory,
|
||||
|
||||
loadAllTags: transactionTag.loadAllTags,
|
||||
saveTag: transactionTag.saveTag,
|
||||
changeTagDisplayOrder: transactionTag.changeTagDisplayOrder,
|
||||
updateTagDisplayOrders: transactionTag.updateTagDisplayOrders,
|
||||
hideTag: transactionTag.hideTag,
|
||||
deleteTag: transactionTag.deleteTag,
|
||||
// transaction tag
|
||||
loadAllTags,
|
||||
saveTag,
|
||||
changeTagDisplayOrder,
|
||||
updateTagDisplayOrders,
|
||||
hideTag,
|
||||
deleteTag,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+4
-11
@@ -7,7 +7,7 @@ import {
|
||||
STORE_USER_INFO
|
||||
} from './mutations.js';
|
||||
|
||||
function getAllTokens() {
|
||||
export function getAllTokens() {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getTokens().then(response => {
|
||||
const data = response.data;
|
||||
@@ -32,7 +32,7 @@ function getAllTokens() {
|
||||
});
|
||||
}
|
||||
|
||||
function refreshTokenAndRevokeOldToken(context) {
|
||||
export function refreshTokenAndRevokeOldToken(context) {
|
||||
return new Promise((resolve) => {
|
||||
services.refreshToken().then(response => {
|
||||
const data = response.data;
|
||||
@@ -57,7 +57,7 @@ function refreshTokenAndRevokeOldToken(context) {
|
||||
});
|
||||
}
|
||||
|
||||
function revokeToken(context, { tokenId, ignoreError }) {
|
||||
export function revokeToken(context, { tokenId, ignoreError }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.revokeToken({
|
||||
tokenId: tokenId,
|
||||
@@ -85,7 +85,7 @@ function revokeToken(context, { tokenId, ignoreError }) {
|
||||
});
|
||||
}
|
||||
|
||||
function revokeAllTokens() {
|
||||
export function revokeAllTokens() {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.revokeAllTokens().then(response => {
|
||||
const data = response.data;
|
||||
@@ -109,10 +109,3 @@ function revokeAllTokens() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
getAllTokens,
|
||||
refreshTokenAndRevokeOldToken,
|
||||
revokeToken,
|
||||
revokeAllTokens
|
||||
}
|
||||
|
||||
+11
-21
@@ -1,9 +1,10 @@
|
||||
import transactionConstants from '../consts/transaction.js';
|
||||
import exchangeRates from "./exchangeRates.js";
|
||||
import services from '../lib/services.js';
|
||||
import logger from '../lib/logger.js';
|
||||
import utils from '../lib/utils.js';
|
||||
|
||||
import { getExchangedAmount } from "./exchangeRates.js";
|
||||
|
||||
import {
|
||||
LOAD_TRANSACTION_LIST,
|
||||
COLLAPSE_MONTH_IN_TRANSACTION_LIST,
|
||||
@@ -17,7 +18,7 @@ const emptyTransactionResult = {
|
||||
transactionsNextTimeId: 0
|
||||
};
|
||||
|
||||
function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime, minTime, type, categoryId, accountId, keyword }) {
|
||||
export function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime, minTime, type, categoryId, accountId, keyword }) {
|
||||
let actualMaxTime = context.state.transactionsNextTimeId;
|
||||
|
||||
if (reload && maxTime > 0) {
|
||||
@@ -91,7 +92,7 @@ function getTransactions(context, { reload, autoExpand, defaultCurrency, maxTime
|
||||
});
|
||||
}
|
||||
|
||||
function getTransaction(context, { transactionId }) {
|
||||
export function getTransaction(context, { transactionId }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getTransaction({
|
||||
id: transactionId
|
||||
@@ -118,7 +119,7 @@ function getTransaction(context, { transactionId }) {
|
||||
});
|
||||
}
|
||||
|
||||
function saveTransaction(context, { transaction }) {
|
||||
export function saveTransaction(context, { transaction }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = null;
|
||||
|
||||
@@ -167,7 +168,7 @@ function saveTransaction(context, { transaction }) {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteTransaction(context, { transaction, defaultCurrency, accountId, beforeResolve }) {
|
||||
export function deleteTransaction(context, { transaction, defaultCurrency, accountId, beforeResolve }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.deleteTransaction({
|
||||
id: transaction.id
|
||||
@@ -212,14 +213,14 @@ function deleteTransaction(context, { transaction, defaultCurrency, accountId, b
|
||||
});
|
||||
}
|
||||
|
||||
function collapseMonthInTransactionList(context, { month, collapse }) {
|
||||
export function collapseMonthInTransactionList(context, { month, collapse }) {
|
||||
context.commit(COLLAPSE_MONTH_IN_TRANSACTION_LIST, {
|
||||
month: month,
|
||||
collapse: collapse
|
||||
});
|
||||
}
|
||||
|
||||
function noTransaction(state) {
|
||||
export function noTransaction(state) {
|
||||
for (let i = 0; i < state.transactions.length; i++) {
|
||||
const transactionMonthList = state.transactions[i];
|
||||
|
||||
@@ -233,11 +234,11 @@ function noTransaction(state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
function hasMoreTransaction(state) {
|
||||
export function hasMoreTransaction(state) {
|
||||
return state.transactionsNextTimeId > 0;
|
||||
}
|
||||
|
||||
function calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, incomplete) {
|
||||
export function calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency, accountId, incomplete) {
|
||||
if (!transactionMonthList) {
|
||||
return;
|
||||
}
|
||||
@@ -257,7 +258,7 @@ function calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency,
|
||||
let amount = transaction.sourceAmount;
|
||||
|
||||
if (transaction.sourceAccount.currency !== defaultCurrency) {
|
||||
const balance = exchangeRates.getExchangedAmount(state)(amount, transaction.sourceAccount.currency, defaultCurrency);
|
||||
const balance = getExchangedAmount(state)(amount, transaction.sourceAccount.currency, defaultCurrency);
|
||||
|
||||
if (!utils.isNumber(balance)) {
|
||||
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
|
||||
@@ -292,14 +293,3 @@ function calculateMonthTotalAmount(state, transactionMonthList, defaultCurrency,
|
||||
incompleteIncome: incomplete || hasUnCalculatedTotalIncome
|
||||
};
|
||||
}
|
||||
|
||||
export default {
|
||||
getTransactions,
|
||||
getTransaction,
|
||||
saveTransaction,
|
||||
deleteTransaction,
|
||||
collapseMonthInTransactionList,
|
||||
noTransaction,
|
||||
hasMoreTransaction,
|
||||
calculateMonthTotalAmount
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
UPDATE_TRANSACTION_CATEGORY_LIST_INVALID_STATE,
|
||||
} from './mutations.js';
|
||||
|
||||
function loadAllCategories(context, { force }) {
|
||||
export function loadAllCategories(context, { force }) {
|
||||
if (!force && !context.state.transactionCategoryListStateInvalid) {
|
||||
return new Promise((resolve) => {
|
||||
resolve(context.state.allTransactionCategories);
|
||||
@@ -78,7 +78,7 @@ function loadAllCategories(context, { force }) {
|
||||
});
|
||||
}
|
||||
|
||||
function getCategory(context, { categoryId }) {
|
||||
export function getCategory(context, { categoryId }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getTransactionCategory({
|
||||
id: categoryId
|
||||
@@ -105,7 +105,7 @@ function getCategory(context, { categoryId }) {
|
||||
});
|
||||
}
|
||||
|
||||
function saveCategory(context, { category }) {
|
||||
export function saveCategory(context, { category }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = null;
|
||||
|
||||
@@ -156,7 +156,7 @@ function saveCategory(context, { category }) {
|
||||
});
|
||||
}
|
||||
|
||||
function addCategories(context, { categories }) {
|
||||
export function addCategories(context, { categories }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.addTransactionCategoryBatch({
|
||||
categories: categories
|
||||
@@ -185,7 +185,7 @@ function addCategories(context, { categories }) {
|
||||
});
|
||||
}
|
||||
|
||||
function changeCategoryDisplayOrder(context, { categoryId, from, to }) {
|
||||
export function changeCategoryDisplayOrder(context, { categoryId, from, to }) {
|
||||
const category = context.state.allTransactionCategoriesMap[categoryId];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
@@ -219,7 +219,7 @@ function changeCategoryDisplayOrder(context, { categoryId, from, to }) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateCategoryDisplayOrders(context, { type, parentId }) {
|
||||
export function updateCategoryDisplayOrders(context, { type, parentId }) {
|
||||
const newDisplayOrders = [];
|
||||
|
||||
let categoryList = null;
|
||||
@@ -267,7 +267,7 @@ function updateCategoryDisplayOrders(context, { type, parentId }) {
|
||||
});
|
||||
}
|
||||
|
||||
function hideCategory(context, { category, hidden }) {
|
||||
export function hideCategory(context, { category, hidden }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.hideTransactionCategory({
|
||||
id: category.id,
|
||||
@@ -309,7 +309,7 @@ function hideCategory(context, { category, hidden }) {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteCategory(context, { category, beforeResolve }) {
|
||||
export function deleteCategory(context, { category, beforeResolve }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.deleteTransactionCategory({
|
||||
id: category.id
|
||||
@@ -343,14 +343,3 @@ function deleteCategory(context, { category, beforeResolve }) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
loadAllCategories,
|
||||
getCategory,
|
||||
saveCategory,
|
||||
addCategories,
|
||||
changeCategoryDisplayOrder,
|
||||
updateCategoryDisplayOrders,
|
||||
hideCategory,
|
||||
deleteCategory,
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
UPDATE_TRANSACTION_TAG_LIST_INVALID_STATE,
|
||||
} from './mutations.js';
|
||||
|
||||
function loadAllTags(context, { force }) {
|
||||
export function loadAllTags(context, { force }) {
|
||||
if (!force && !context.state.transactionTagListStateInvalid) {
|
||||
return new Promise((resolve) => {
|
||||
resolve(context.state.allTransactionTags);
|
||||
@@ -49,7 +49,7 @@ function loadAllTags(context, { force }) {
|
||||
});
|
||||
}
|
||||
|
||||
function saveTag(context, { tag }) {
|
||||
export function saveTag(context, { tag }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = null;
|
||||
|
||||
@@ -96,7 +96,7 @@ function saveTag(context, { tag }) {
|
||||
});
|
||||
}
|
||||
|
||||
function changeTagDisplayOrder(context, { tagId, from, to }) {
|
||||
export function changeTagDisplayOrder(context, { tagId, from, to }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let tag = null;
|
||||
|
||||
@@ -123,7 +123,7 @@ function changeTagDisplayOrder(context, { tagId, from, to }) {
|
||||
});
|
||||
}
|
||||
|
||||
function updateTagDisplayOrders(context) {
|
||||
export function updateTagDisplayOrders(context) {
|
||||
const newDisplayOrders = [];
|
||||
|
||||
for (let i = 0; i < context.state.allTransactionTags.length; i++) {
|
||||
@@ -161,7 +161,7 @@ function updateTagDisplayOrders(context) {
|
||||
});
|
||||
}
|
||||
|
||||
function hideTag(context, { tag, hidden }) {
|
||||
export function hideTag(context, { tag, hidden }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.hideTransactionTag({
|
||||
id: tag.id,
|
||||
@@ -203,7 +203,7 @@ function hideTag(context, { tag, hidden }) {
|
||||
});
|
||||
}
|
||||
|
||||
function deleteTag(context, { tag, beforeResolve }) {
|
||||
export function deleteTag(context, { tag, beforeResolve }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.deleteTransactionTag({
|
||||
id: tag.id
|
||||
@@ -237,12 +237,3 @@ function deleteTag(context, { tag, beforeResolve }) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
loadAllTags,
|
||||
saveTag,
|
||||
changeTagDisplayOrder,
|
||||
updateTagDisplayOrders,
|
||||
hideTag,
|
||||
deleteTag,
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import services from '../lib/services.js';
|
||||
import logger from '../lib/logger.js';
|
||||
import utils from '../lib/utils.js';
|
||||
|
||||
function get2FAStatus() {
|
||||
export function get2FAStatus() {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.get2FAStatus().then(response => {
|
||||
const data = response.data;
|
||||
@@ -28,7 +28,7 @@ function get2FAStatus() {
|
||||
});
|
||||
}
|
||||
|
||||
function enable2FA() {
|
||||
export function enable2FA() {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.enable2FA().then(response => {
|
||||
const data = response.data;
|
||||
@@ -53,7 +53,7 @@ function enable2FA() {
|
||||
});
|
||||
}
|
||||
|
||||
function confirmEnable2FA(context, { secret, passcode }) {
|
||||
export function confirmEnable2FA(context, { secret, passcode }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.confirmEnable2FA({
|
||||
secret: secret,
|
||||
@@ -85,7 +85,7 @@ function confirmEnable2FA(context, { secret, passcode }) {
|
||||
});
|
||||
}
|
||||
|
||||
function disable2FA(context, { password }) {
|
||||
export function disable2FA(context, { password }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.disable2FA({
|
||||
password: password
|
||||
@@ -112,7 +112,7 @@ function disable2FA(context, { password }) {
|
||||
});
|
||||
}
|
||||
|
||||
function regenerate2FARecoveryCode(context, { password }) {
|
||||
export function regenerate2FARecoveryCode(context, { password }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.regenerate2FARecoveryCode({
|
||||
password: password
|
||||
@@ -138,11 +138,3 @@ function regenerate2FARecoveryCode(context, { password }) {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default {
|
||||
get2FAStatus,
|
||||
enable2FA,
|
||||
confirmEnable2FA,
|
||||
disable2FA,
|
||||
regenerate2FARecoveryCode
|
||||
}
|
||||
|
||||
+10
-23
@@ -11,7 +11,7 @@ import {
|
||||
CLEAR_USER_INFO
|
||||
} from './mutations.js';
|
||||
|
||||
function authorize(context, { loginName, password }) {
|
||||
export function authorize(context, { loginName, password }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.authorize({
|
||||
loginName: loginName,
|
||||
@@ -61,7 +61,7 @@ function authorize(context, { loginName, password }) {
|
||||
});
|
||||
}
|
||||
|
||||
function authorize2FA(context, { token, passcode, recoveryCode }) {
|
||||
export function authorize2FA(context, { token, passcode, recoveryCode }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let promise = null;
|
||||
|
||||
@@ -120,7 +120,7 @@ function authorize2FA(context, { token, passcode, recoveryCode }) {
|
||||
});
|
||||
}
|
||||
|
||||
function register(context, { user }) {
|
||||
export function register(context, { user }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.register({
|
||||
username: user.username,
|
||||
@@ -165,7 +165,7 @@ function register(context, { user }) {
|
||||
});
|
||||
}
|
||||
|
||||
function logout(context) {
|
||||
export function logout(context) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.logout().then(response => {
|
||||
const data = response.data;
|
||||
@@ -196,7 +196,7 @@ function logout(context) {
|
||||
});
|
||||
}
|
||||
|
||||
function getCurrentUserProfile() {
|
||||
export function getCurrentUserProfile() {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.getProfile().then(response => {
|
||||
const data = response.data;
|
||||
@@ -221,7 +221,7 @@ function getCurrentUserProfile() {
|
||||
});
|
||||
}
|
||||
|
||||
function updateUserProfile(context, { profile, currentPassword }) {
|
||||
export function updateUserProfile(context, { profile, currentPassword }) {
|
||||
return new Promise((resolve, reject) => {
|
||||
services.updateProfile({
|
||||
password: profile.password,
|
||||
@@ -260,33 +260,20 @@ function updateUserProfile(context, { profile, currentPassword }) {
|
||||
});
|
||||
}
|
||||
|
||||
function clearUserInfoState(context) {
|
||||
export function clearUserInfoState(context) {
|
||||
context.commit(CLEAR_USER_INFO);
|
||||
}
|
||||
|
||||
function resetState(context) {
|
||||
export function resetState(context) {
|
||||
context.commit(RESET_STATE);
|
||||
}
|
||||
|
||||
function currentUserNickname(state) {
|
||||
export function currentUserNickname(state) {
|
||||
const userInfo = state.currentUserInfo || {};
|
||||
return userInfo.nickname || userInfo.username || null;
|
||||
}
|
||||
|
||||
function currentUserDefaultCurrency(state) {
|
||||
export function currentUserDefaultCurrency(state) {
|
||||
const userInfo = state.currentUserInfo || {};
|
||||
return userInfo.defaultCurrency || null;
|
||||
}
|
||||
|
||||
export default {
|
||||
authorize,
|
||||
authorize2FA,
|
||||
register,
|
||||
logout,
|
||||
getCurrentUserProfile,
|
||||
updateUserProfile,
|
||||
clearUserInfoState,
|
||||
resetState,
|
||||
currentUserNickname,
|
||||
currentUserDefaultCurrency
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user