migrate to typescript

This commit is contained in:
MaysWind
2024-12-29 14:24:37 +08:00
parent b638a73e4d
commit 2560a70e5e
171 changed files with 3402 additions and 2557 deletions
+32 -32
View File
@@ -3,13 +3,13 @@ import { defineStore } from 'pinia';
import { useUserStore } from './user.js';
import { useExchangeRatesStore } from './exchangeRates.js';
import accountConstants from '@/consts/account.js';
import currencyConstants from '@/consts/currency.js';
import iconConstants from '@/consts/icon.js';
import colorConstants from '@/consts/color.js';
import { AccountType, AccountCategory } from '@/core/account.ts';
import { PARENT_ACCOUNT_CURRENCY_PLACEHOLDER } from '@/consts/currency.ts';
import { DEFAULT_ACCOUNT_ICON_ID } from '@/consts/icon.ts';
import { DEFAULT_ACCOUNT_COLOR } from '@/consts/color.ts';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
import { isNumber, isEquals } from '@/lib/common.js';
import { isNumber, isEquals } from '@/lib/common.ts';
import { getCurrentUnixTime } from '@/lib/datetime.js';
import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.js';
@@ -185,9 +185,9 @@ export const useAccountsStore = defineStore('accounts', {
for (let i = 0; i < state.allAccounts.length; i++) {
const account = state.allAccounts[i];
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
allAccounts.push(account);
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
} else if (account.type === AccountType.MultiSubAccounts.type) {
if (account.subAccounts) {
for (let j = 0; j < account.subAccounts.length; j++) {
const subAccount = account.subAccounts[j];
@@ -209,9 +209,9 @@ export const useAccountsStore = defineStore('accounts', {
continue;
}
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
allVisibleAccounts.push(account);
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
} else if (account.type === AccountType.MultiSubAccounts.type) {
if (account.subAccounts) {
for (let j = 0; j < account.subAccounts.length; j++) {
const subAccount = account.subAccounts[j];
@@ -262,11 +262,11 @@ export const useAccountsStore = defineStore('accounts', {
const now = getCurrentUnixTime();
return {
category: accountConstants.cashCategoryType,
type: accountConstants.allAccountTypes.SingleAccount,
category: AccountCategory.Cash.type,
type: AccountType.SingleAccount.type,
name: '',
icon: iconConstants.defaultAccountIconId,
color: colorConstants.defaultAccountColor,
icon: DEFAULT_ACCOUNT_ICON_ID,
color: DEFAULT_ACCOUNT_COLOR,
currency: userStore.currentUserDefaultCurrency,
balance: 0,
balanceTime: now,
@@ -321,7 +321,7 @@ export const useAccountsStore = defineStore('accounts', {
for (let i = 0; i < accounts.length; i++) {
const account = accounts[i];
if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && account.subAccounts) {
if (account.type === AccountType.MultiSubAccounts.type && account.subAccounts) {
for (let j = 0; j < account.subAccounts.length; j++) {
const subAccount = account.subAccounts[j];
@@ -361,7 +361,7 @@ export const useAccountsStore = defineStore('accounts', {
for (let i = accounts.length - 1; i >= 0; i--) {
const account = accounts[i];
if (account.type === accountConstants.allAccountTypes.MultiSubAccounts && account.subAccounts) {
if (account.type === AccountType.MultiSubAccounts.type && account.subAccounts) {
for (let j = account.subAccounts.length - 1; j >= 0; j--) {
const subAccount = account.subAccounts[j];
@@ -416,7 +416,7 @@ export const useAccountsStore = defineStore('accounts', {
return null;
}
if (mainAccount.category === accountConstants.creditCardCategoryType) {
if (mainAccount.category === AccountCategory.CreditCard.type) {
return mainAccount.creditCardStatementDate;
}
@@ -525,7 +525,7 @@ export const useAccountsStore = defineStore('accounts', {
const userStore = useUserStore();
const exchangeRatesStore = useExchangeRatesStore();
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccountsMap, account => account.category === accountCategory.id);
const accountsBalance = getAllFilteredAccountsBalance(this.allCategorizedAccountsMap, account => account.category === accountCategory.type);
let totalBalance = 0;
let hasUnCalculatedAmount = false;
@@ -563,7 +563,7 @@ export const useAccountsStore = defineStore('accounts', {
}
},
getAccountBalance(showAccountBalance, account) {
if (account.type !== accountConstants.allAccountTypes.SingleAccount) {
if (account.type !== AccountType.SingleAccount.type) {
return null;
}
@@ -580,7 +580,7 @@ export const useAccountsStore = defineStore('accounts', {
}
},
getAccountSubAccountBalance(showAccountBalance, showHidden, account, subAccountId) {
if (account.type !== accountConstants.allAccountTypes.MultiSubAccounts) {
if (account.type !== AccountType.MultiSubAccounts.type) {
return null;
}
@@ -681,16 +681,16 @@ export const useAccountsStore = defineStore('accounts', {
};
},
hasAccount(accountCategory, visibleOnly) {
if (!this.allCategorizedAccountsMap[accountCategory.id] ||
!this.allCategorizedAccountsMap[accountCategory.id].accounts ||
!this.allCategorizedAccountsMap[accountCategory.id].accounts.length) {
if (!this.allCategorizedAccountsMap[accountCategory.type] ||
!this.allCategorizedAccountsMap[accountCategory.type].accounts ||
!this.allCategorizedAccountsMap[accountCategory.type].accounts.length) {
return false;
}
let shownCount = 0;
for (let i = 0; i < this.allCategorizedAccountsMap[accountCategory.id].accounts.length; i++) {
const account = this.allCategorizedAccountsMap[accountCategory.id].accounts[i];
for (let i = 0; i < this.allCategorizedAccountsMap[accountCategory.type].accounts.length; i++) {
const account = this.allCategorizedAccountsMap[accountCategory.type].accounts[i];
if (!visibleOnly || !account.hidden) {
shownCount++;
@@ -700,7 +700,7 @@ export const useAccountsStore = defineStore('accounts', {
return shownCount > 0;
},
hasVisibleSubAccount(showHidden, account) {
if (!account || account.type !== accountConstants.allAccountTypes.MultiSubAccounts || !account.subAccounts) {
if (!account || account.type !== AccountType.MultiSubAccounts.type || !account.subAccounts) {
return false;
}
@@ -792,12 +792,12 @@ export const useAccountsStore = defineStore('accounts', {
const submitSubAccounts = [];
if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
if (account.type === AccountType.MultiSubAccounts.type) {
for (let i = 0; i < subAccounts.length; i++) {
const subAccount = subAccounts[i];
const submitAccount = {
category: account.category,
type: accountConstants.allAccountTypes.SingleAccount,
type: AccountType.SingleAccount.type,
name: subAccount.name,
icon: subAccount.icon,
color: subAccount.color,
@@ -823,13 +823,13 @@ export const useAccountsStore = defineStore('accounts', {
name: account.name,
icon: account.icon,
color: account.color,
currency: account.type === accountConstants.allAccountTypes.SingleAccount ? account.currency : currencyConstants.parentAccountCurrencyPlaceholder,
balance: account.type === accountConstants.allAccountTypes.SingleAccount ? account.balance : 0,
currency: account.type === AccountType.SingleAccount.type ? account.currency : PARENT_ACCOUNT_CURRENCY_PLACEHOLDER,
balance: account.type === AccountType.SingleAccount.type ? account.balance : 0,
comment: account.comment,
subAccounts: account.type === accountConstants.allAccountTypes.SingleAccount ? null : submitSubAccounts,
subAccounts: account.type === AccountType.SingleAccount.type ? null : submitSubAccounts,
};
if (account.category === accountConstants.creditCardCategoryType) {
if (account.category === AccountCategory.CreditCard.type) {
submitAccount.creditCardStatementDate = account.creditCardStatementDate;
}
@@ -841,7 +841,7 @@ export const useAccountsStore = defineStore('accounts', {
submitAccount.id = account.id;
submitAccount.hidden = !account.visible;
} else {
if (account.type === accountConstants.allAccountTypes.SingleAccount) {
if (account.type === AccountType.SingleAccount.type) {
submitAccount.balanceTime = account.balanceTime;
}
}
+1 -1
View File
@@ -2,7 +2,7 @@ import { defineStore } from 'pinia';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
import { isEquals } from '@/lib/common.js';
import { isEquals } from '@/lib/common.ts';
import { getCurrentUnixTime, formatUnixTime } from '@/lib/datetime.js';
import { getExchangedAmount } from '@/lib/numeral.js';
+1 -1
View File
@@ -14,7 +14,7 @@ import { useExchangeRatesStore } from './exchangeRates.js';
import userState from '@/lib/userstate.js';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
import { isObject, isString } from '@/lib/common.js';
import { isObject, isString } from '@/lib/common.ts';
export const useRootStore = defineStore('root', {
state: () => ({
+1 -1
View File
@@ -4,7 +4,7 @@ import { useSettingsStore } from '@/stores/setting.js';
import { useUserStore } from './user.js';
import { useExchangeRatesStore } from './exchangeRates.js';
import { isNumber, isEquals } from '@/lib/common.js';
import { isNumber, isEquals } from '@/lib/common.ts';
import {
getUnixTimeBeforeUnixTime,
getTodayFirstUnixTime,
+2 -2
View File
@@ -1,6 +1,6 @@
import { defineStore } from 'pinia';
import currencyConstants from '@/consts/currency.js';
import { DEFAULT_CURRENCY_CODE } from '@/consts/currency.ts';
import datetimeConstants from '@/consts/datetime.js';
import * as settings from '@/lib/settings.js';
@@ -36,7 +36,7 @@ export const useSettingsStore = defineStore('settings', {
animate: settings.isEnableAnimate()
},
localeDefaultSettings: {
currency: currencyConstants.defaultCurrency,
currency: DEFAULT_CURRENCY_CODE,
firstDayOfWeek: datetimeConstants.defaultFirstDayOfWeek
}
}),
+19 -19
View File
@@ -6,12 +6,12 @@ import { useAccountsStore } from './account.js';
import { useTransactionCategoriesStore } from './transactionCategory.js';
import { useExchangeRatesStore } from './exchangeRates.js';
import { CategoryType } from '@/core/category.ts';
import { TransactionTagFilterType } from '@/core/transaction.ts';
import datetimeConstants from '@/consts/datetime.js';
import transactionConstants from '@/consts/transaction.js';
import statisticsConstants from '@/consts/statistics.js';
import categoryConstants from '@/consts/category.js';
import iconConstants from '@/consts/icon.js';
import colorConstants from '@/consts/color.js';
import { DEFAULT_ACCOUNT_ICON, DEFAULT_CATEGORY_ICON } from '@/consts/icon.ts';
import { DEFAULT_ACCOUNT_COLOR, DEFAULT_CATEGORY_COLOR } from '@/consts/color.ts';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
import {
@@ -24,7 +24,7 @@ import {
isYearMonthEquals,
isObjectEmpty,
objectFieldToArrayItem
} from '@/lib/common.js';
} from '@/lib/common.ts';
import {
getYearAndMonthFromUnixTime,
getDateRangeByDateType
@@ -105,14 +105,14 @@ function getCategoryTotalAmountItems(items, transactionStatisticsFilter) {
transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.ExpenseByPrimaryCategory.type ||
transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.ExpenseBySecondaryCategory.type ||
transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.TotalExpense.type) {
if (item.category.type !== categoryConstants.allCategoryTypes.Expense) {
if (item.category.type !== CategoryType.Expense) {
continue;
}
} else if (transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByAccount.type ||
transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByPrimaryCategory.type ||
transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeBySecondaryCategory.type ||
transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.TotalIncome.type) {
if (item.category.type !== categoryConstants.allCategoryTypes.Income) {
if (item.category.type !== CategoryType.Income) {
continue;
}
} else if (transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.TotalBalance.type) {
@@ -141,8 +141,8 @@ function getCategoryTotalAmountItems(items, transactionStatisticsFilter) {
name: item.account.name,
type: 'account',
id: item.account.id,
icon: item.account.icon || iconConstants.defaultAccountIcon.icon,
color: item.account.color || colorConstants.defaultAccountColor,
icon: item.account.icon || DEFAULT_ACCOUNT_ICON.icon,
color: item.account.color || DEFAULT_ACCOUNT_COLOR,
hidden: item.primaryAccount.hidden || item.account.hidden,
displayOrders: [item.primaryAccount.category, item.primaryAccount.displayOrder, item.account.displayOrder],
totalAmount: item.amountInDefaultCurrency
@@ -169,8 +169,8 @@ function getCategoryTotalAmountItems(items, transactionStatisticsFilter) {
name: item.primaryCategory.name,
type: 'category',
id: item.primaryCategory.id,
icon: item.primaryCategory.icon || iconConstants.defaultCategoryIcon.icon,
color: item.primaryCategory.color || colorConstants.defaultCategoryColor,
icon: item.primaryCategory.icon || DEFAULT_CATEGORY_ICON.icon,
color: item.primaryCategory.color || DEFAULT_CATEGORY_COLOR,
hidden: item.primaryCategory.hidden,
displayOrders: [item.primaryCategory.type, item.primaryCategory.displayOrder],
totalAmount: item.amountInDefaultCurrency
@@ -197,8 +197,8 @@ function getCategoryTotalAmountItems(items, transactionStatisticsFilter) {
name: item.category.name,
type: 'category',
id: item.category.id,
icon: item.category.icon || iconConstants.defaultCategoryIcon.icon,
color: item.category.color || colorConstants.defaultCategoryColor,
icon: item.category.icon || DEFAULT_CATEGORY_ICON.icon,
color: item.category.color || DEFAULT_CATEGORY_COLOR,
hidden: item.primaryCategory.hidden || item.category.hidden,
displayOrders: [item.primaryCategory.type, item.primaryCategory.displayOrder, item.category.displayOrder],
totalAmount: item.amountInDefaultCurrency
@@ -221,7 +221,7 @@ function getCategoryTotalAmountItems(items, transactionStatisticsFilter) {
let amount = item.amountInDefaultCurrency;
if (transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.TotalBalance.type &&
item.category.type === categoryConstants.allCategoryTypes.Expense) {
item.category.type === CategoryType.Expense) {
amount = -amount;
}
@@ -287,7 +287,7 @@ export const useStatisticsStore = defineStore('statistics', {
filterAccountIds: {},
filterCategoryIds: {},
tagIds: '',
tagFilterType: transactionConstants.defaultTransactionTagFilterType.type
tagFilterType: TransactionTagFilterType.Default.type
},
transactionCategoryStatisticsData: {},
transactionCategoryTrendsData: {},
@@ -389,8 +389,8 @@ export const useStatisticsStore = defineStore('statistics', {
name: account.name,
type: 'account',
id: account.id,
icon: account.icon || iconConstants.defaultAccountIcon.icon,
color: account.color || colorConstants.defaultAccountColor,
icon: account.icon || DEFAULT_ACCOUNT_ICON.icon,
color: account.color || DEFAULT_ACCOUNT_COLOR,
hidden: primaryAccount.hidden || account.hidden,
displayOrders: [primaryAccount.category, primaryAccount.displayOrder, account.displayOrder],
totalAmount: amount
@@ -565,7 +565,7 @@ export const useStatisticsStore = defineStore('statistics', {
this.transactionStatisticsFilter.filterAccountIds = {};
this.transactionStatisticsFilter.filterCategoryIds = {};
this.transactionStatisticsFilter.tagIds = '';
this.transactionStatisticsFilter.tagFilterType = transactionConstants.defaultTransactionTagFilterType.type;
this.transactionStatisticsFilter.tagFilterType = TransactionTagFilterType.Default.type;
this.transactionCategoryStatisticsData = {};
this.transactionCategoryTrendsData = {};
this.transactionStatisticsStateInvalid = true;
@@ -694,7 +694,7 @@ export const useStatisticsStore = defineStore('statistics', {
if (filter && isInteger(filter.tagFilterType)) {
this.transactionStatisticsFilter.tagFilterType = filter.tagFilterType;
} else {
this.transactionStatisticsFilter.tagFilterType = transactionConstants.defaultTransactionTagFilterType.type;
this.transactionStatisticsFilter.tagFilterType = TransactionTagFilterType.Default.type;
}
if (filter && isInteger(filter.sortingType)) {
+1 -1
View File
@@ -5,7 +5,7 @@ import { useUserStore } from './user.js';
import userState from '@/lib/userstate.js';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
import { isObject } from '@/lib/common.js';
import { isObject } from '@/lib/common.ts';
export const useTokensStore = defineStore('tokens', {
actions: {
+37 -36
View File
@@ -8,9 +8,10 @@ import { useOverviewStore } from './overview.js';
import { useStatisticsStore } from './statistics.js';
import { useExchangeRatesStore } from './exchangeRates.js';
import { CategoryType } from '@/core/category.ts';
import { TransactionType, TransactionTagFilterType } from '@/core/transaction.ts';
import { TRANSACTION_MIN_AMOUNT, TRANSACTION_MAX_AMOUNT } from '@/consts/transaction.ts';
import datetimeConstants from '@/consts/datetime.js';
import categoryConstants from '@/consts/category.js';
import transactionConstants from '@/consts/transaction.js';
import userState from '@/lib/userstate.js';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
@@ -18,7 +19,7 @@ import {
isDefined,
isNumber,
isString
} from '@/lib/common.js';
} from '@/lib/common.ts';
import {
getCurrentUnixTime,
getTimezoneOffsetMinutes,
@@ -33,7 +34,7 @@ import {
getDayOfWeekName
} from '@/lib/datetime.js';
import { getAmountWithDecimalNumberCount } from '@/lib/numeral.js';
import { getCurrencyFraction } from '@/lib/currency.js';
import { getCurrencyFraction } from '@/lib/currency.ts';
import { getFirstAvailableCategoryId } from '@/lib/category.js';
const emptyTransactionResult = {
@@ -233,9 +234,9 @@ function calculateMonthTotalAmount(exchangeRatesStore, transactionMonthList, def
const balance = exchangeRatesStore.getExchangedAmount(amount, account.currency, defaultCurrency);
if (!isNumber(balance)) {
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
if (transaction.type === TransactionType.Expense) {
hasUnCalculatedTotalExpense = true;
} else if (transaction.type === transactionConstants.allTransactionTypes.Income) {
} else if (transaction.type === TransactionType.Income) {
hasUnCalculatedTotalIncome = true;
}
@@ -245,11 +246,11 @@ function calculateMonthTotalAmount(exchangeRatesStore, transactionMonthList, def
amount = balance;
}
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
if (transaction.type === TransactionType.Expense) {
totalExpense += amount;
} else if (transaction.type === transactionConstants.allTransactionTypes.Income) {
} else if (transaction.type === TransactionType.Income) {
totalIncome += amount;
} else if (transaction.type === transactionConstants.allTransactionTypes.Transfer && totalAccountIdsCount > 0) {
} else if (transaction.type === TransactionType.Transfer && totalAccountIdsCount > 0) {
if (allAccountIdsMap[transaction.sourceAccountId] && allAccountIdsMap[transaction.destinationAccountId]) {
// Do Nothing
} else if (transaction.sourceAccount && transaction.destinationAccount && allAccountIdsMap[transaction.sourceAccount.parentId] && allAccountIdsMap[transaction.destinationAccount.parentId]) {
@@ -317,7 +318,7 @@ function buildBasicSubmitTransaction(transaction, dummyTime) {
utcOffset: transaction.utcOffset
};
if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
if (transaction.type === TransactionType.Transfer) {
submitTransaction.destinationAccountId = transaction.destinationAccountId;
submitTransaction.destinationAmount = transaction.destinationAmount;
}
@@ -332,11 +333,11 @@ function buildTransactionDraft(transaction) {
let categoryId = '';
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
if (transaction.type === TransactionType.Expense) {
categoryId = transaction.expenseCategory;
} else if (transaction.type === transactionConstants.allTransactionTypes.Income) {
} else if (transaction.type === TransactionType.Income) {
categoryId = transaction.incomeCategory;
} else if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
} else if (transaction.type === TransactionType.Transfer) {
categoryId = transaction.transferCategory;
} else {
return null;
@@ -355,7 +356,7 @@ function buildTransactionDraft(transaction) {
comment: transaction.comment,
};
if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
if (transaction.type === TransactionType.Transfer) {
transactionDraft.destinationAccountId = transaction.destinationAccountId;
transactionDraft.destinationAmount = transaction.destinationAmount;
}
@@ -374,7 +375,7 @@ export const useTransactionsStore = defineStore('transactions', {
categoryIds: '',
accountIds: '',
tagIds: '',
tagFilterType: transactionConstants.defaultTransactionTagFilterType.type,
tagFilterType: TransactionTagFilterType.Default.type,
amountFilter: '',
keyword: ''
},
@@ -518,7 +519,7 @@ export const useTransactionsStore = defineStore('transactions', {
return true;
}
if (transaction.type === transactionConstants.allTransactionTypes.Transfer && transaction.destinationAmount !== 0) {
if (transaction.type === TransactionType.Transfer && transaction.destinationAmount !== 0) {
return true;
}
@@ -526,27 +527,27 @@ export const useTransactionsStore = defineStore('transactions', {
return true;
}
if (transaction.type === transactionConstants.allTransactionTypes.Transfer && transaction.destinationAccountId && transaction.destinationAccountId !== '0' && transaction.destinationAccountId !== userStore.currentUserDefaultAccountId) {
if (transaction.type === TransactionType.Transfer && transaction.destinationAccountId && transaction.destinationAccountId !== '0' && transaction.destinationAccountId !== userStore.currentUserDefaultAccountId) {
return true;
}
const allCategories = transactionCategoriesStore.allTransactionCategories;
if (allCategories) {
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[categoryConstants.allCategoryTypes.Expense]);
if (transaction.type === TransactionType.Expense) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[CategoryType.Expense]);
if (transaction.expenseCategory && transaction.expenseCategory !== '0' && transaction.expenseCategory !== defaultCategoryId) {
return true;
}
} else if (transaction.type === transactionConstants.allTransactionTypes.Income) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[categoryConstants.allCategoryTypes.Income]);
} else if (transaction.type === TransactionType.Income) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[CategoryType.Income]);
if (transaction.incomeCategory && transaction.incomeCategory !== '0' && transaction.incomeCategory !== defaultCategoryId) {
return true;
}
} else if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[categoryConstants.allCategoryTypes.Transfer]);
} else if (transaction.type === TransactionType.Transfer) {
const defaultCategoryId = getFirstAvailableCategoryId(allCategories[CategoryType.Transfer]);
if (transaction.transferCategory && transaction.transferCategory !== '0' && transaction.transferCategory !== defaultCategoryId) {
return true;
@@ -600,12 +601,12 @@ export const useTransactionsStore = defineStore('transactions', {
const now = getCurrentUnixTime();
const currentTimezone = settingsStore.appSettings.timeZone;
let defaultType = transactionConstants.allTransactionTypes.Expense;
let defaultType = TransactionType.Expense;
if (type === transactionConstants.allTransactionTypes.Income.toString()) {
defaultType = transactionConstants.allTransactionTypes.Income;
} else if (type === transactionConstants.allTransactionTypes.Transfer.toString()) {
defaultType = transactionConstants.allTransactionTypes.Transfer;
if (type === TransactionType.Income.toString()) {
defaultType = TransactionType.Income;
} else if (type === TransactionType.Transfer.toString()) {
defaultType = TransactionType.Transfer;
}
return {
@@ -631,9 +632,9 @@ export const useTransactionsStore = defineStore('transactions', {
const accountsStore = useAccountsStore();
const exchangeRatesStore = useExchangeRatesStore();
if (transaction.type === transactionConstants.allTransactionTypes.Expense || transaction.type === transactionConstants.allTransactionTypes.Income) {
if (transaction.type === TransactionType.Expense || transaction.type === TransactionType.Income) {
transaction.destinationAmount = newValue;
} else if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
} else if (transaction.type === TransactionType.Transfer) {
const sourceAccount = accountsStore.allAccountsMap[transaction.sourceAccountId];
const destinationAccount = accountsStore.allAccountsMap[transaction.destinationAccountId];
@@ -656,7 +657,7 @@ export const useTransactionsStore = defineStore('transactions', {
}
if ((!sourceAccount || !destinationAccount || transaction.destinationAmount === oldValue || transaction.destinationAmount === 0) &&
(transactionConstants.minAmountNumber <= newValue && newValue <= transactionConstants.maxAmountNumber)) {
(TRANSACTION_MIN_AMOUNT <= newValue && newValue <= TRANSACTION_MAX_AMOUNT)) {
transaction.destinationAmount = newValue;
}
}
@@ -672,7 +673,7 @@ export const useTransactionsStore = defineStore('transactions', {
this.transactionsFilter.categoryIds = '';
this.transactionsFilter.accountIds = '';
this.transactionsFilter.tagIds = '';
this.transactionsFilter.tagFilterType = transactionConstants.defaultTransactionTagFilterType.type;
this.transactionsFilter.tagFilterType = TransactionTagFilterType.Default.type;
this.transactionsFilter.amountFilter = '';
this.transactionsFilter.keyword = '';
this.transactions = [];
@@ -730,7 +731,7 @@ export const useTransactionsStore = defineStore('transactions', {
if (filter && isNumber(filter.tagFilterType)) {
this.transactionsFilter.tagFilterType = filter.tagFilterType;
} else {
this.transactionsFilter.tagFilterType = transactionConstants.defaultTransactionTagFilterType.type;
this.transactionsFilter.tagFilterType = TransactionTagFilterType.Default.type;
}
if (filter && isString(filter.amountFilter)) {
@@ -1043,11 +1044,11 @@ export const useTransactionsStore = defineStore('transactions', {
const submitTransaction = buildBasicSubmitTransaction(transaction, true);
if (transaction.type === transactionConstants.allTransactionTypes.Expense) {
if (transaction.type === TransactionType.Expense) {
submitTransaction.categoryId = transaction.expenseCategory;
} else if (transaction.type === transactionConstants.allTransactionTypes.Income) {
} else if (transaction.type === TransactionType.Income) {
submitTransaction.categoryId = transaction.incomeCategory;
} else if (transaction.type === transactionConstants.allTransactionTypes.Transfer) {
} else if (transaction.type === TransactionType.Transfer) {
submitTransaction.categoryId = transaction.transferCategory;
} else {
return Promise.reject('An error occurred');
+13 -13
View File
@@ -1,9 +1,9 @@
import { defineStore } from 'pinia';
import categoryConstants from '@/consts/category.js';
import iconConstants from '@/consts/icon.js';
import colorConstants from '@/consts/color.js';
import { isEquals } from '@/lib/common.js';
import { CategoryType } from '@/core/category.ts';
import { DEFAULT_CATEGORY_ICON_ID } from '@/consts/icon.ts';
import { DEFAULT_CATEGORY_COLOR } from '@/consts/color.ts';
import { isEquals } from '@/lib/common.ts';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
@@ -139,11 +139,11 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
actions: {
generateNewTransactionCategoryModel(type, parentId) {
return {
type: type || categoryConstants.allCategoryTypes.Income,
type: type || CategoryType.Income,
name: '',
parentId: parentId || '0',
icon: iconConstants.defaultCategoryIconId,
color: colorConstants.defaultCategoryColor,
icon: DEFAULT_CATEGORY_ICON_ID,
color: DEFAULT_CATEGORY_COLOR,
comment: '',
visible: true
};
@@ -174,16 +174,16 @@ export const useTransactionCategoriesStore = defineStore('transactionCategories'
return;
}
if (!data.result[categoryConstants.allCategoryTypes.Income]) {
data.result[categoryConstants.allCategoryTypes.Income] = [];
if (!data.result[CategoryType.Income]) {
data.result[CategoryType.Income] = [];
}
if (!data.result[categoryConstants.allCategoryTypes.Expense]) {
data.result[categoryConstants.allCategoryTypes.Expense] = [];
if (!data.result[CategoryType.Expense]) {
data.result[CategoryType.Expense] = [];
}
if (!data.result[categoryConstants.allCategoryTypes.Transfer]) {
data.result[categoryConstants.allCategoryTypes.Transfer] = [];
if (!data.result[CategoryType.Transfer]) {
data.result[CategoryType.Transfer] = [];
}
for (let categoryType in data.result) {
+1 -1
View File
@@ -1,6 +1,6 @@
import { defineStore } from 'pinia';
import { isEquals } from '@/lib/common.js';
import { isEquals } from '@/lib/common.ts';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
+7 -7
View File
@@ -1,8 +1,8 @@
import { defineStore } from 'pinia';
import transactionConstants from '@/consts/transaction.js';
import templateConstants from '@/consts/template.js';
import { isDefined, isObject, isArray, isEquals } from '@/lib/common.js';
import { TransactionType } from '@/core/transaction.ts';
import { TemplateType } from '@/core/template.ts';
import { isDefined, isObject, isArray, isEquals } from '@/lib/common.ts';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
@@ -231,17 +231,17 @@ export const useTransactionTemplatesStore = defineStore('transactionTemplates',
submitTemplate.clientSessionId = clientSessionId;
}
if (template.templateType === templateConstants.allTemplateTypes.Schedule) {
if (template.templateType === TemplateType.Schedule.type) {
submitTemplate.scheduledFrequencyType = template.scheduledFrequencyType;
submitTemplate.scheduledFrequency = template.scheduledFrequency;
submitTemplate.utcOffset = template.utcOffset;
}
if (template.type === transactionConstants.allTransactionTypes.Expense) {
if (template.type === TransactionType.Expense) {
submitTemplate.categoryId = template.expenseCategory;
} else if (template.type === transactionConstants.allTransactionTypes.Income) {
} else if (template.type === TransactionType.Income) {
submitTemplate.categoryId = template.incomeCategory;
} else if (template.type === transactionConstants.allTransactionTypes.Transfer) {
} else if (template.type === TransactionType.Transfer) {
submitTemplate.categoryId = template.transferCategory;
submitTemplate.destinationAccountId = template.destinationAccountId;
submitTemplate.destinationAmount = template.destinationAmount;
+1 -1
View File
@@ -3,7 +3,7 @@ import { defineStore } from 'pinia';
import userState from '@/lib/userstate.js';
import services from '@/lib/services.js';
import logger from '@/lib/logger.js';
import { isBoolean } from '@/lib/common.js';
import { isBoolean } from '@/lib/common.ts';
export const useTwoFactorAuthStore = defineStore('twoFactorAuth', {
actions: {
+1 -1
View File
@@ -8,7 +8,7 @@ import logger from '@/lib/logger.js';
import {
isObject,
isNumber
} from '@/lib/common.js';
} from '@/lib/common.ts';
export const useUserStore = defineStore('user', {
state: () => ({