diff --git a/.eslintrc.cjs b/.eslintrc.cjs index defd0337..cbe88616 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -18,10 +18,7 @@ module.exports = { }, }, { - files: [ - "**/__tests__/*.{j,t}s?(x)", - "**/tests/unit/**/*.spec.{j,t}s?(x)", - ], + files: ["**/__tests__/*.{j,t}s?(x)", "**/tests/unit/**/*.spec.{j,t}s?(x)"], }, ], diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index ec873090..194bf6b4 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -8,3 +8,7 @@ # prettier format of the whole project e29b83e463be79f1b8a548b8608c4aad9812be78 + +# prettier format of the project after switch to max-len: 100 +1bd66a9b898bad9e01987da2ba1d1dfbd18bc537 +16ba277502c3b556bbdfca6e19ee731611b12f72 diff --git a/.prettierrc.json b/.prettierrc.json index 0967ef42..ad4bde9a 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1,5 @@ -{} +{ + "printWidth": 100, + "tabWidth": 2, + "useTabs": false +} diff --git a/backend b/backend index a968eb55..fa424fcb 160000 --- a/backend +++ b/backend @@ -1 +1 @@ -Subproject commit a968eb5550fc9dcc6f362e6b9c9e10a6696e73db +Subproject commit fa424fcb2771e287b127bf2a948c649b3bf74de5 diff --git a/package-lock.json b/package-lock.json index 96a1b9ee..bd4c28b9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -68,7 +68,7 @@ "storybook-dark-mode": "^4.0.2", "tailwindcss": "^3.4.8", "typescript": "^5.5.4", - "vite": "^5.4.0", + "vite": "^5.4.2", "vite-svg-loader": "^5.1.0", "vitest": "^2.0.5", "vue-style-loader": "^4.1.3", @@ -14890,14 +14890,14 @@ } }, "node_modules/vite": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.0.tgz", - "integrity": "sha512-5xokfMX0PIiwCMCMb9ZJcMyh5wbBun0zUzKib+L65vAZ8GY9ePZMXxFrHbr/Kyll2+LSCY7xtERPpxkBDKngwg==", + "version": "5.4.2", + "resolved": "https://registry.npmjs.org/vite/-/vite-5.4.2.tgz", + "integrity": "sha512-dDrQTRHp5C1fTFzcSaMxjk6vdpKvT+2/mIdE07Gw2ykehT49O0z/VHS3zZ8iV/Gh8BJJKHWOe5RjaNrW5xf/GA==", "dev": true, "dependencies": { "esbuild": "^0.21.3", - "postcss": "^8.4.40", - "rollup": "^4.13.0" + "postcss": "^8.4.41", + "rollup": "^4.20.0" }, "bin": { "vite": "bin/vite.js" diff --git a/package.json b/package.json index 8621f377..92804caf 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "storybook-dark-mode": "^4.0.2", "tailwindcss": "^3.4.8", "typescript": "^5.5.4", - "vite": "^5.4.0", + "vite": "^5.4.2", "vite-svg-loader": "^5.1.0", "vitest": "^2.0.5", "vue-style-loader": "^4.1.3", diff --git a/src/api/_api.ts b/src/api/_api.ts index 3bc3b4ef..6976cc4a 100644 --- a/src/api/_api.ts +++ b/src/api/_api.ts @@ -2,10 +2,7 @@ import { API_ERROR_CODES, API_RESPONSE_STATUS } from "shared-types"; import { useAuthStore } from "@/stores"; import { router } from "@/routes"; import { ApiBaseError } from "@/common/types"; -import { - useNotificationCenter, - NotificationType, -} from "@/components/notification-center"; +import { useNotificationCenter, NotificationType } from "@/components/notification-center"; import * as errors from "@/js/errors"; diff --git a/src/api/accounts.ts b/src/api/accounts.ts index 56b07be4..42c11bbd 100644 --- a/src/api/accounts.ts +++ b/src/api/accounts.ts @@ -23,10 +23,8 @@ export const createAccount = async ( ): Promise => { const params = payload; - if (params.creditLimit) - params.creditLimit = toSystemAmount(Number(params.creditLimit)); - if (params.initialBalance) - params.initialBalance = toSystemAmount(Number(params.initialBalance)); + if (params.creditLimit) params.creditLimit = toSystemAmount(Number(params.creditLimit)); + if (params.initialBalance) params.initialBalance = toSystemAmount(Number(params.initialBalance)); const result = await api.post("/accounts", { ...params, @@ -45,10 +43,8 @@ export const editAccount = async ({ }): Promise => { const params = data; - if (params.creditLimit) - params.creditLimit = toSystemAmount(Number(params.creditLimit)); - if (params.currentBalance) - params.currentBalance = toSystemAmount(Number(params.currentBalance)); + if (params.creditLimit) params.creditLimit = toSystemAmount(Number(params.creditLimit)); + if (params.currentBalance) params.currentBalance = toSystemAmount(Number(params.currentBalance)); const result = await api.put(`/accounts/${id}`, params); @@ -58,6 +54,5 @@ export const editAccount = async ({ export interface DeleteAccountPayload { id: number; } -export const deleteAccount = async ({ - id, -}: DeleteAccountPayload): Promise => api.delete(`/accounts/${id}`); +export const deleteAccount = async ({ id }: DeleteAccountPayload): Promise => + api.delete(`/accounts/${id}`); diff --git a/src/api/auth.ts b/src/api/auth.ts index 5eb9900f..023ce00e 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -3,10 +3,8 @@ import { api } from "@/api/_api"; export const authLogin = async ( payload: endpointsTypes.AuthLoginBody, -): Promise => - api.post("/auth/login", payload); +): Promise => api.post("/auth/login", payload); export const authRegister = async ( payload: endpointsTypes.AuthRegisterBody, -): Promise => - api.post("/auth/register", payload); +): Promise => api.post("/auth/register", payload); diff --git a/src/api/categories.ts b/src/api/categories.ts index 6f19a640..933169b7 100644 --- a/src/api/categories.ts +++ b/src/api/categories.ts @@ -26,10 +26,6 @@ export const editCategory = async ({ return result; }; -export const deleteCategory = async ({ - categoryId, -}: { - categoryId: number; -}) => { +export const deleteCategory = async ({ categoryId }: { categoryId: number }) => { await api.delete(`/categories/${categoryId}`); }; diff --git a/src/api/currencies.ts b/src/api/currencies.ts index 3b1a4ac7..e740b5ec 100644 --- a/src/api/currencies.ts +++ b/src/api/currencies.ts @@ -1,12 +1,7 @@ import { api } from "@/api/_api"; -import { - CurrencyModel, - UserExchangeRatesModel, - UserCurrencyModel, -} from "shared-types"; +import { CurrencyModel, UserExchangeRatesModel, UserCurrencyModel } from "shared-types"; -export const getAllCurrencies = async (): Promise => - api.get("/models/currencies"); +export const getAllCurrencies = async (): Promise => api.get("/models/currencies"); export const loadUserCurrencies = async (): Promise => api.get("/user/currencies"); @@ -18,9 +13,8 @@ export const deleteCustomRate = ( }[], ) => api.delete("/user/currency/rates", { pairs }); -export const loadUserCurrenciesExchangeRates = async (): Promise< - UserExchangeRatesModel[] -> => api.get("/user/currencies/rates"); +export const loadUserCurrenciesExchangeRates = async (): Promise => + api.get("/user/currencies/rates"); export const editUserCurrenciesExchangeRates = async ( pairs: { @@ -28,8 +22,7 @@ export const editUserCurrenciesExchangeRates = async ( quoteCode: string; rate: number; }[], -): Promise => - api.put("/user/currency/rates", { pairs }); +): Promise => api.put("/user/currency/rates", { pairs }); export const deleteUserCurrency = (currencyId: number) => api.delete("/user/currency", { currencyId }); diff --git a/src/api/monobank.ts b/src/api/monobank.ts index 4da2805f..b2e16d18 100644 --- a/src/api/monobank.ts +++ b/src/api/monobank.ts @@ -15,9 +15,8 @@ export const loadMonoTransactions = async ( ): Promise => api.get("/banks/monobank/load-transactions", payload); -export const updateMonoWebhook = async ( - payload: endpointsTypes.UpdateWebhookBody, -): Promise => api.post("/banks/monobank/update-webhook", payload); +export const updateMonoWebhook = async (payload: endpointsTypes.UpdateWebhookBody): Promise => + api.post("/banks/monobank/update-webhook", payload); export const updateMonoUser = async ( payload: endpointsTypes.UpdateMonobankUserBody, diff --git a/src/api/refunds.ts b/src/api/refunds.ts new file mode 100644 index 00000000..9356c76e --- /dev/null +++ b/src/api/refunds.ts @@ -0,0 +1,29 @@ +import { api } from "@/api/_api"; +import { TransactionModel } from "shared-types"; +import { formatTransactionResponse } from "./transactions"; + +export const linkRefund = async (params: { originalTxId: number | null; refundTxId: number }) => + api.post("/transactions/refund", params); + +type GetRefundsResponse = { + id: number; + originalTxId: number; + refundTxId: number; + originalTransaction: TransactionModel; + refundTransaction: TransactionModel; +}[]; + +export const getRefundsForTransaction = async (params: { + transactionId: number; +}): Promise => { + const result: GetRefundsResponse = await api.get( + `/transactions/${params.transactionId}/refunds`, + params, + ); + + return result.map((i) => ({ + ...i, + originalTransaction: formatTransactionResponse(i.originalTransaction), + refundTransaction: formatTransactionResponse(i.refundTransaction), + })); +}; diff --git a/src/api/stats.ts b/src/api/stats.ts index ddc959d4..8ca1e692 100644 --- a/src/api/stats.ts +++ b/src/api/stats.ts @@ -17,11 +17,9 @@ export interface BalanceHistoryEntity { accountId: number; } -export const getBalanceHistory = async ({ - from, - to, - ...rest -}: Params = {}): Promise => { +export const getBalanceHistory = async ({ from, to, ...rest }: Params = {}): Promise< + BalanceHistoryEntity[] +> => { const params: endpointsTypes.GetBalanceHistoryPayload = { ...rest, }; @@ -29,10 +27,7 @@ export const getBalanceHistory = async ({ if (from) params.from = formatDate(from); if (to) params.to = formatDate(to); - const history: BalanceHistoryEntity[] = await api.get( - "/stats/balance-history", - params, - ); + const history: BalanceHistoryEntity[] = await api.get("/stats/balance-history", params); return history.map((item) => ({ ...item, @@ -52,10 +47,7 @@ export const getExpensesAmountForPeriod = async ({ if (from) params.from = formatDate(from); if (to) params.to = formatDate(to); - const amount: number = await api.get( - "/stats/expenses-amount-for-period", - params, - ); + const amount: number = await api.get("/stats/expenses-amount-for-period", params); return fromSystemAmount(amount); }; @@ -72,7 +64,14 @@ export const getSpendingsByCategories = async ({ if (from) params.from = formatDate(from); if (to) params.to = formatDate(to); - const history = await api.get("/stats/spendings-by-categories", params); + const history: endpointsTypes.GetSpendingsByCategoriesReturnType = await api.get( + "/stats/spendings-by-categories", + params, + ); + + Object.keys(history).forEach((id) => { + history[id].amount = fromSystemAmount(history[id].amount); + }); return history; }; diff --git a/src/api/transactions.ts b/src/api/transactions.ts index 739737ce..4b0cfb73 100644 --- a/src/api/transactions.ts +++ b/src/api/transactions.ts @@ -1,14 +1,8 @@ -import { - TransactionModel, - endpointsTypes, - TRANSACTION_TRANSFER_NATURE, -} from "shared-types"; +import { TransactionModel, endpointsTypes, TRANSACTION_TRANSFER_NATURE } from "shared-types"; import { api } from "@/api/_api"; import { fromSystemAmount, toSystemAmount } from "@/api/helpers"; -const formatTransactionResponse = ( - transaction: TransactionModel, -): TransactionModel => ({ +export const formatTransactionResponse = (transaction: TransactionModel): TransactionModel => ({ ...transaction, amount: fromSystemAmount(transaction.amount), refAmount: fromSystemAmount(transaction.refAmount), @@ -17,7 +11,7 @@ const formatTransactionResponse = ( commissionRate: fromSystemAmount(transaction.commissionRate), }); -const formatTransactionPayload = (transaction: T): T => { +export const formatTransactionPayload = (transaction: T): T => { const params = transaction; const fieldsToPatch = ["amount", "destinationAmount"]; @@ -36,11 +30,7 @@ export const loadTransactions = async ( return result.map((item) => formatTransactionResponse(item)); }; -export const loadTransactionById = async ({ - id, -}: { - id: number; -}): Promise => { +export const loadTransactionById = async ({ id }: { id: number }): Promise => { const result = await api.get(`/transactions/${id}`); return formatTransactionResponse(result); @@ -54,9 +44,7 @@ export const loadTransactionsByTransferId = async ( return result.map((item) => formatTransactionResponse(item)); }; -export const createTransaction = async ( - params: endpointsTypes.CreateTransactionBody, -) => { +export const createTransaction = async (params: endpointsTypes.CreateTransactionBody) => { try { const formattedParams = formatTransactionPayload({ transferNature: TRANSACTION_TRANSFER_NATURE.not_transfer, @@ -64,7 +52,7 @@ export const createTransaction = async ( ...params, }); - await api.post("/transactions", formattedParams); + return api.post("/transactions", formattedParams); } catch (e) { throw new Error(e); } diff --git a/src/common/const/vue-query.ts b/src/common/const/vue-query.ts index ce66c867..b6775b49 100644 --- a/src/common/const/vue-query.ts +++ b/src/common/const/vue-query.ts @@ -6,33 +6,21 @@ export const VUE_QUERY_CACHE_KEYS = Object.freeze({ // widget balance trend widgetBalanceTrend: [TX_CHANGE_QUERY, "widget-balance-trend"], widgetBalanceTotalBalance: [TX_CHANGE_QUERY, "widget-balance-total-balance"], - widgetBalancePreviousBalance: [ - TX_CHANGE_QUERY, - "widget-balance-previous-balance", - ], + widgetBalancePreviousBalance: [TX_CHANGE_QUERY, "widget-balance-previous-balance"], // widget expenses structure - widgetExpensesStructureTotal: [ - TX_CHANGE_QUERY, - "widget-expenses-structure-total", - ], + widgetExpensesStructureTotal: [TX_CHANGE_QUERY, "widget-expenses-structure-total"], widgetExpensesStructureCurrentAmount: [ TX_CHANGE_QUERY, "widget-expenses-structure-current-amount", ], - widgetExpensesStructurePrevAmount: [ - TX_CHANGE_QUERY, - "widget-expenses-structure-prev-amount", - ], + widgetExpensesStructurePrevAmount: [TX_CHANGE_QUERY, "widget-expenses-structure-prev-amount"], // widget latest records widgetLatestRecords: [TX_CHANGE_QUERY, "widget-latest-records"], // others - analyticsBalanceHistoryTrend: [ - TX_CHANGE_QUERY, - "analytics-balance-history-trend", - ], + analyticsBalanceHistoryTrend: [TX_CHANGE_QUERY, "analytics-balance-history-trend"], recordsPageRecordsList: [TX_CHANGE_QUERY, "records-page-records-list"], diff --git a/src/common/utils/color-theme.ts b/src/common/utils/color-theme.ts index 7b0186de..0b19ef0d 100644 --- a/src/common/utils/color-theme.ts +++ b/src/common/utils/color-theme.ts @@ -19,10 +19,7 @@ export const setTheme = (theme: Themes, save = false) => { }; export const toggleTheme = () => { - setTheme( - currentTheme.value === Themes.dark ? Themes.light : Themes.dark, - true, - ); + setTheme(currentTheme.value === Themes.dark ? Themes.light : Themes.dark, true); }; export const identifyCurrentTheme = () => { diff --git a/src/components/common/tooltip.vue b/src/components/common/tooltip.vue index 2b4def91..174656ff 100644 --- a/src/components/common/tooltip.vue +++ b/src/components/common/tooltip.vue @@ -2,9 +2,7 @@
-