Open source personal finance application
chore(typo): refactor and typo fixes
ilkome475d511f3122
diff --git a/components/categories/getCategories.ts b/components/categories/getCategories.tsindex 765359b0..1ca0f932 100644--- a/components/categories/getCategories.ts+++ b/components/categories/getCategories.ts@@ -13,7 +13,7 @@ export function getCatsIds(catsIds, catsItems) {}// TODO: add typings-export function getTransferCatgoriesIds(categoriesItems) {+export function getTransferCategoriesIds(categoriesItems) {const names = ['перевод', 'transfer']const categoriesIdsByName = Object.keys(categoriesItems)diff --git a/components/stat/StatItemChildCats.vue b/components/stat/StatItemChildCats.vueindex a0c3f0af..5b09bb1c 100644--- a/components/stat/StatItemChildCats.vue+++ b/components/stat/StatItemChildCats.vue@@ -50,13 +50,6 @@ export default {trnsIds = trnsIds.filter(id => trns[id].type === this.type)return trnsIds},-- getCategoryStat({ categoryId, trnsIds }) {- return {- categoryId,- ...this.$store.getters['trns/getTotalOfTrnsIds'](trnsIds),- }- },},}</script>diff --git a/components/stat/group/Chart.vue b/components/stat/group/Chart.vuedeleted file mode 100644index 7346e619..00000000--- a/components/stat/group/Chart.vue+++ /dev/null@@ -1,279 +0,0 @@-<script>-import { Chart } from 'highcharts-vue'-import chartOptions from '~/components/stat/chartOptions'-import useChart from '~/components/chart/useChart'-import useFilter from '~/modules/filter/useFilter'-import { getTrnsIds } from '~/components/trns/getTrns'--export default {- name: 'StatChartLines',-- components: { Chart },-- props: {- isShowIncomes: { type: Boolean, default: true },- isShowExpenses: { type: Boolean, default: true },- categoryId: { type: String, default: null },- amountType: { type: String, default: null },- },-- setup() {- const { $store } = useNuxtApp()- const { isShowDataLabels } = useChart()- const { filterPeriodNameAllReplacedToYear, scrollTop } = useFilter()-- const periods = computed(() => $store.state.chart.periods)- const chartType = computed(() => {- let type = null- periods.value[filterPeriodNameAllReplacedToYear.value].grouped- ? type = 'column'- : type = 'spline'-- return type- })-- const chartObj = ref({})- const chartCallback = (v) => { chartObj.value = v }-- const onClickChart = async (event) => {- const chart = chartObj.value- if (!chart)- return-- const nEvent = await chart.pointer.normalize(event)- let date = chart.series[0].searchPoint(nEvent, true)?.date || chart.series[1].searchPoint(nEvent, true)?.date || chart.series[2].searchPoint(nEvent, true)?.date- setTimeout(() => {- date = chart.series[0].searchPoint(nEvent, true)?.date || chart.series[1].searchPoint(nEvent, true)?.date || chart.series[2].searchPoint(nEvent, true)?.date- if (date) {- if ($store.state.filter.period === 'all')- $store.dispatch('filter/setPeriod', 'year')-- $store.dispatch('filter/setDate', parseInt(date))- scrollTop()- }- }, 100)- }-- watch(() => $store.state.filter.date, async () => {- await nextTick()-- const chart = chartObj.value- if (!chartObj.value)- return-- const chartSeriesIdx = chart.series[0].options.data.findIndex(v => +v.date === +$store.state.filter.date)- if (chartSeriesIdx !== -1) {- chart.xAxis[0].update({- plotBands: [{- color: 'var(--c-item-bg-active)',- from: chartSeriesIdx + 0.5,- to: chartSeriesIdx - 0.5,- }],- })- }- }, { immediate: true })-- return {- onClickChart,- chartCallback,- isShowDataLabels,- chartType,- filterPeriodNameAllReplacedToYear,- scrollTop,- }- },-- computed: {- chartData() {- const periodName = this.filterPeriodNameAllReplacedToYear- const chartPeriods = this.$store.state.chart.periods- const trnsItems = this.$store.state.trns.items-- // diff periods from oldest trn and today- const oldestTrnDate = this.$day(trnsItems[this.$store.getters['trns/firstCreatedTrnId']].date).endOf(periodName)- let periodsToShow = this.$day().endOf(periodName).diff(oldestTrnDate, periodName) + 1- const periodsWantToShow = chartPeriods[periodName].showedPeriods- periodsToShow = periodsWantToShow >= periodsToShow ? periodsToShow : periodsWantToShow-- const categories = []- const incomesData = []- const expensesData = []- const totalData = []-- for (let index = 0; index < periodsToShow; index++) {- // count total period- const periodDate = this.$day().startOf(periodName).subtract(index, periodName).valueOf()-- const trnsIds = getTrnsIds({- categoriesIds: [this.categoryId],- periodName,- date: periodDate,- trnsItems,- })-- const periodTotal = this.$store.getters['trns/getTotalOfTrnsIds'](trnsIds)-- let format = 'MM'- if (periodName === 'day')- format = 'D.MM'- if (periodName === 'week')- format = 'D MMM'- if (periodName === 'month')- format = 'MMM'- if (periodName === 'year')- format = 'YYYY'- const name = this.$day().startOf(periodName).subtract(index, periodName).format(format)-- // Incomes- incomesData.unshift({- date: periodDate,- y: Number(`${periodTotal.incomes.toFixed()}`),- })- // Expenses- expensesData.unshift({- date: periodDate,- y: Number(`${periodTotal.expenses.toFixed()}`),- })- // Total- totalData.unshift({- date: periodDate,- y: Number(`${(periodTotal.total).toFixed()}`),- })- categories.unshift(name)- }-- let periods = 0- let periodsTotalIncomes = 0- for (const iterator of incomesData) {- if (iterator.y !== 0) {- periods = periods + 1- periodsTotalIncomes = periodsTotalIncomes + iterator.y- }- }- let periodsExpenses = 0- let periodsTotalExpenses = 0- for (const iterator of expensesData) {- if (iterator.y !== 0) {- periodsExpenses = periodsExpenses + 1- periodsTotalExpenses = periodsTotalExpenses + iterator.y- }- }-- const fakeLineDate = expensesData.map(i => ({ date: i.date, y: periodsTotalIncomes / periods || periodsTotalExpenses / periodsExpenses }))-- const data = {- series: [{- zIndex: 3,- visible: periodsTotalIncomes > 0 && this.isShowIncomes,- type: this.chartType,- name: this.$t('money.incomes'),- color: 'var(--c-incomes-1)',- data: incomesData,- marker: {- lineColor: 'var(--c-incomes-1)',- },- }, {- zIndex: 2,- visible: periodsTotalExpenses > 0 && this.isShowExpenses,- type: this.chartType,- name: this.$t('money.expenses'),- color: 'var(--c-expenses-1)',- data: expensesData,- marker: {- lineColor: 'var(--c-expenses-1)',- },- // Fake data to make good hover on bar chart- }, {- zIndex: 1,- visible: true,- type: 'line',- name: '',- color: 'transparent',- data: fakeLineDate,- marker: {- enabled: false,- symbol: 'circle',- radius: 0,- lineWidth: 0,- states: {- hover: {- fillColor: 'transparent',- lineColor: 'transparent',- lineWidth: 0,- },- },- },- dataLabels: {- enabled: false,- },- }],- categories,- averageIncomes: periodsTotalIncomes / periods,- averageExpenses: periodsTotalExpenses / periodsExpenses,- }-- const tooltip = this.$store.state.ui.pc ? { ...chartOptions.tooltip } : { enabled: false }-- return {- ...chartOptions,- legend: false,- tooltip,-- series: data.series,-- xAxis: {- ...chartOptions.xAxis,- categories: data.categories,- },-- yAxis: {- ...chartOptions.yAxis,- plotLines: [{- opacity: 0.5,- color: 'var(--c-expenses-opacity)',- value: data.averageExpenses,- width: '2',- zIndex: 1,- }, {- opacity: 0.5,- color: 'var(--c-incomes-opacity)',- value: data.averageIncomes,- width: '2',- zIndex: 1,- }],- },-- chart: {- ...chartOptions.chart,- height: '180',- },-- plotOptions: {- ...chartOptions.plotOptions,- series: {- ...chartOptions.plotOptions.series,- dataLabels: {- ...chartOptions.plotOptions.series.dataLabels,- enabled: this.isShowDataLabels,- },- },- },- }- },- },-}-</script>--<template lang="pug">-.chart(@click="onClickChart")- Chart(- :options="chartData"- :callback="chartCallback"- )-</template>--<style lang="stylus" scoped>-.chart- z-index 3- position relative-</style>diff --git a/components/trnForm/SelectedTransfer.vue b/components/trnForm/SelectedTransfer.vueindex ccce6edd..d1cf0900 100644--- a/components/trnForm/SelectedTransfer.vue+++ b/components/trnForm/SelectedTransfer.vue@@ -9,7 +9,6 @@ const expenseWalletId = computed(() => {return expenseWalletId || walletFromId || firstWalletId})const expenseWallet = computed(() => $store.state.wallets.items[expenseWalletId.value])-const expenseWalletTotal = computed(() => $store.getters['wallets/walletsTotal'][expenseWalletId.value].base)// Incomeconst incomeWalletId = computed(() => {@@ -19,7 +18,6 @@ const incomeWalletId = computed(() => {return incomeWalletId || walletToId || secondWalletId})const incomeWallet = computed(() => $store.state.wallets.items[incomeWalletId.value])-const incomeWalletTotal = computed(() => $store.getters['wallets/walletsTotal'][incomeWalletId.value].base)if ($store.state.trnForm.values.amountType === 2) {$store.commit('trnForm/setTrnFormValues', {@@ -28,7 +26,7 @@ if ($store.state.trnForm.values.amountType === 2) {})}-const isSameCurency = computed(() => incomeWallet.value?.currency === expenseWallet.value?.currency)+const isSameCurrency = computed(() => incomeWallet.value?.currency === expenseWallet.value?.currency)function changeAmount(TransferType: 'income' | 'expense', event: any) {$store.commit('trnForm/setTrnFormValues', {@@ -39,8 +37,8 @@ function changeAmount(TransferType: 'income' | 'expense', event: any) {<template lang="pug">div(v-if="$store.getters['wallets/walletsSortedIds'].length > 1")- //- isSameCurency- template(v-if="!isSameCurency")+ //- isSameCurrency+ template(v-if="!isSameCurrency").pb-8.px-4.grid.gap-6(class="grid-cols-[1fr_auto]").grid.gap-6div@@ -86,7 +84,7 @@ div(v-if="$store.getters['wallets/walletsSortedIds'].length > 1").mdi.mdi-equal//- Same- .relative.px-3.pb-6.grid.grid-cols-2.gap-3(v-if="isSameCurency")+ .relative.px-3.pb-6.grid.grid-cols-2.gap-3(v-if="isSameCurrency")//- Transfer expensediv(v-if="expenseWallet"diff --git a/components/trnForm/TrnForm.vue b/components/trnForm/TrnForm.vueindex f8c910e5..98302d1f 100644--- a/components/trnForm/TrnForm.vue+++ b/components/trnForm/TrnForm.vue@@ -37,7 +37,7 @@ const incomeWalletId = computed(() => {})const incomeWallet = computed(() => $store.state.wallets.items[incomeWalletId.value])-const isSameCurency = computed(() => incomeWallet.value?.currency === expenseWallet.value?.currency)+const isSameCurrency = computed(() => incomeWallet.value?.currency === expenseWallet.value?.currency)/*** Slider@@ -151,9 +151,9 @@ function prepeareValues(): any {type: 2,description: $store.state.trnForm.values.description || null,groups: $store.state.trnForm.values.groups || null,- expenseAmount: isSameCurency.value ? getResult.value : $store.state.trnForm.values.expenseAmount,+ expenseAmount: isSameCurrency.value ? getResult.value : $store.state.trnForm.values.expenseAmount,expenseWalletId: $store.state.trnForm.values.expenseWalletId,- incomeAmount: isSameCurency.value ? getResult.value : $store.state.trnForm.values.incomeAmount,+ incomeAmount: isSameCurrency.value ? getResult.value : $store.state.trnForm.values.incomeAmount,incomeWalletId: $store.state.trnForm.values.incomeWalletId,}}@@ -217,11 +217,11 @@ function handleSubmitForm() {temaplte(v-if="!$store.state.trnForm.values.trnId") {{ $t('trnForm.titleCreateTrn') }}TrnFormTypes- TrnFormAmount(v-if="!isTransfer || isTransfer && isSameCurency")+ TrnFormAmount(v-if="!isTransfer || isTransfer && isSameCurrency")TrnFormDateTrnFormCalculator(- v-if="!isTransfer || isTransfer && isSameCurency"+ v-if="!isTransfer || isTransfer && isSameCurrency"@onSubmit="handleSubmitForm")TrnFormSelecteddiff --git a/pages/wallets/total.vue b/pages/wallets/total.vueindex c11b9f46..dbdcafc5 100644--- a/pages/wallets/total.vue+++ b/pages/wallets/total.vue@@ -8,7 +8,7 @@ import type { PeriodsNamesExeptAll } from '~/components/date/types'import type { TrnID, TrnItem } from '~/components/trns/types'import useAmount from '~/components/amount/useAmount'import { averageLine, baseSeriesItemStyle, options } from '~/components/chart/chartOprions'-import { getTransferCatgoriesIds } from '~/components/categories/getCategories'+import { getTransferCategoriesIds } from '~/components/categories/getCategories'import { getTotal } from '~/components/trns/getTotal'import { getTrnsIds } from '~/components/trns/getTrns'@@ -102,7 +102,7 @@ const series = computed(() => periodshey.value.map((period) => {const walletsItems = $store.state.wallets.itemsconst baseRate = $store.state.currencies.baseconst rates = $store.state.currencies.rates- const transferCategoriesIds = getTransferCatgoriesIds(categoriesItems)+ const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)const total = getTotal({baseRate,rates,diff --git a/store/categories/getters.js b/store/categories/getters.jsindex c616a58b..9761eb22 100644--- a/store/categories/getters.js+++ b/store/categories/getters.js@@ -43,7 +43,7 @@ export default {break}}- // TODO: use new getTransferCatgoriesIds+ // TODO: use new getTransferCategoriesIdsif (!hasTrnsIn && categoryId !== 'transfer' && categories[categoryId].name.toLowerCase() !== 'перевод' && categories[categoryId].name.toLowerCase() !== 'transfer')categoriesForBeParent.push(categoryId)}@@ -127,7 +127,7 @@ export default {if (!getters.hasCategories)return null- // TODO: use new getTransferCatgoriesIds+ // TODO: use new getTransferCategoriesIdsreturn Object.keys(state.items).find(id => state.items[id].name === 'Перевод' || state.items[id].name === 'Transfer') || state.items.transfer},diff --git a/store/trns/getters.js b/store/trns/getters.jsindex dc5ba0ce..792bf595 100644--- a/store/trns/getters.js+++ b/store/trns/getters.js@@ -1,5 +1,5 @@import dayjs from 'dayjs'-import { getCatsIds, getTransferCatgoriesIds } from '~/components/categories/getCategories'+import { getCatsIds, getTransferCategoriesIds } from '~/components/categories/getCategories'import { getTotal } from '~/components/trns/getTotal'import { getTrnsIds } from '~/components/trns/getTrns'@@ -28,7 +28,7 @@ export default {const walletsItems = rootState.wallets.itemsconst categoriesItems = rootState.categories.itemsconst baseRate = rootState.currencies.base- const transferCategoriesIds = getTransferCatgoriesIds(categoriesItems)+ const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)let total = 0diff --git a/tests/getTotal.test.ts b/tests/getTotal.test.tsindex f5ac2e96..fc5a45e5 100644--- a/tests/getTotal.test.ts+++ b/tests/getTotal.test.ts@@ -1,12 +1,12 @@import { describe, expect, it } from 'vitest'import { categoriesItems } from '~/tests/categories.mock'import { getTotal } from '~/components/trns/getTotal'-import { getTransferCatgoriesIds } from '~/components/categories/getCategories'+import { getTransferCategoriesIds } from '~/components/categories/getCategories'import { trnsItems } from '~/tests/trns.mock'import { walletsItems } from '~/tests/wallets.mock'import { ratesBasedOnUsd as rates } from '~/tests/rates.mock'-const transferCategoriesIds = getTransferCatgoriesIds(categoriesItems)+const transferCategoriesIds = getTransferCategoriesIds(categoriesItems)describe('Total of Transactions', () => {it('Correct empty result and correct total structure', () => {