Skip to content

Commit

Permalink
Merge pull request #303 from letehaha/feat/refund-functionality
Browse files Browse the repository at this point in the history
feat: Refund functionality
  • Loading branch information
letehaha committed Aug 29, 2024
2 parents 84cfc18 + 3792e97 commit e1b099a
Show file tree
Hide file tree
Showing 138 changed files with 1,859 additions and 1,680 deletions.
5 changes: 1 addition & 4 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"],
},
],

Expand Down
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@

# prettier format of the whole project
e29b83e463be79f1b8a548b8608c4aad9812be78

# prettier format of the project after switch to max-len: 100
1bd66a9b898bad9e01987da2ba1d1dfbd18bc537
16ba277502c3b556bbdfca6e19ee731611b12f72
6 changes: 5 additions & 1 deletion .prettierrc.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"printWidth": 100,
"tabWidth": 2,
"useTabs": false
}
2 changes: 1 addition & 1 deletion backend
Submodule backend updated 113 files
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 1 addition & 4 deletions src/api/_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
17 changes: 6 additions & 11 deletions src/api/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ export const createAccount = async (
): Promise<AccountModel> => {
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,
Expand All @@ -45,10 +43,8 @@ export const editAccount = async ({
}): Promise<AccountModel> => {
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);

Expand All @@ -58,6 +54,5 @@ export const editAccount = async ({
export interface DeleteAccountPayload {
id: number;
}
export const deleteAccount = async ({
id,
}: DeleteAccountPayload): Promise<void> => api.delete(`/accounts/${id}`);
export const deleteAccount = async ({ id }: DeleteAccountPayload): Promise<void> =>
api.delete(`/accounts/${id}`);
6 changes: 2 additions & 4 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { api } from "@/api/_api";

export const authLogin = async (
payload: endpointsTypes.AuthLoginBody,
): Promise<endpointsTypes.AuthLoginResponse> =>
api.post("/auth/login", payload);
): Promise<endpointsTypes.AuthLoginResponse> => api.post("/auth/login", payload);

export const authRegister = async (
payload: endpointsTypes.AuthRegisterBody,
): Promise<endpointsTypes.AuthRegisterResponse> =>
api.post("/auth/register", payload);
): Promise<endpointsTypes.AuthRegisterResponse> => api.post("/auth/register", payload);
6 changes: 1 addition & 5 deletions src/api/categories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
};
17 changes: 5 additions & 12 deletions src/api/currencies.ts
Original file line number Diff line number Diff line change
@@ -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<CurrencyModel[]> =>
api.get("/models/currencies");
export const getAllCurrencies = async (): Promise<CurrencyModel[]> => api.get("/models/currencies");

export const loadUserCurrencies = async (): Promise<UserCurrencyModel[]> =>
api.get("/user/currencies");
Expand All @@ -18,18 +13,16 @@ 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<UserExchangeRatesModel[]> =>
api.get("/user/currencies/rates");

export const editUserCurrenciesExchangeRates = async (
pairs: {
baseCode: string;
quoteCode: string;
rate: number;
}[],
): Promise<UserExchangeRatesModel[]> =>
api.put("/user/currency/rates", { pairs });
): Promise<UserExchangeRatesModel[]> => api.put("/user/currency/rates", { pairs });

export const deleteUserCurrency = (currencyId: number) =>
api.delete("/user/currency", { currencyId });
Expand Down
5 changes: 2 additions & 3 deletions src/api/monobank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ export const loadMonoTransactions = async (
): Promise<endpointsTypes.LoadMonoTransactionsResponse> =>
api.get("/banks/monobank/load-transactions", payload);

export const updateMonoWebhook = async (
payload: endpointsTypes.UpdateWebhookBody,
): Promise<void> => api.post("/banks/monobank/update-webhook", payload);
export const updateMonoWebhook = async (payload: endpointsTypes.UpdateWebhookBody): Promise<void> =>
api.post("/banks/monobank/update-webhook", payload);

export const updateMonoUser = async (
payload: endpointsTypes.UpdateMonobankUserBody,
Expand Down
29 changes: 29 additions & 0 deletions src/api/refunds.ts
Original file line number Diff line number Diff line change
@@ -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<GetRefundsResponse> => {
const result: GetRefundsResponse = await api.get(
`/transactions/${params.transactionId}/refunds`,
params,
);

return result.map((i) => ({
...i,
originalTransaction: formatTransactionResponse(i.originalTransaction),
refundTransaction: formatTransactionResponse(i.refundTransaction),
}));
};
27 changes: 13 additions & 14 deletions src/api/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,17 @@ export interface BalanceHistoryEntity {
accountId: number;
}

export const getBalanceHistory = async ({
from,
to,
...rest
}: Params = {}): Promise<BalanceHistoryEntity[]> => {
export const getBalanceHistory = async ({ from, to, ...rest }: Params = {}): Promise<
BalanceHistoryEntity[]
> => {
const params: endpointsTypes.GetBalanceHistoryPayload = {
...rest,
};

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,
Expand All @@ -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);
};
Expand All @@ -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;
};
Expand Down
24 changes: 6 additions & 18 deletions src/api/transactions.ts
Original file line number Diff line number Diff line change
@@ -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),
Expand All @@ -17,7 +11,7 @@ const formatTransactionResponse = (
commissionRate: fromSystemAmount(transaction.commissionRate),
});

const formatTransactionPayload = <T>(transaction: T): T => {
export const formatTransactionPayload = <T>(transaction: T): T => {
const params = transaction;
const fieldsToPatch = ["amount", "destinationAmount"];

Expand All @@ -36,11 +30,7 @@ export const loadTransactions = async (
return result.map((item) => formatTransactionResponse(item));
};

export const loadTransactionById = async ({
id,
}: {
id: number;
}): Promise<TransactionModel> => {
export const loadTransactionById = async ({ id }: { id: number }): Promise<TransactionModel> => {
const result = await api.get(`/transactions/${id}`);

return formatTransactionResponse(result);
Expand All @@ -54,17 +44,15 @@ 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,
note: "",
...params,
});

await api.post("/transactions", formattedParams);
return api.post("/transactions", formattedParams);
} catch (e) {
throw new Error(e);
}
Expand Down
20 changes: 4 additions & 16 deletions src/common/const/vue-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"],

Expand Down
5 changes: 1 addition & 4 deletions src/common/utils/color-theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down
4 changes: 1 addition & 3 deletions src/components/common/tooltip.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
<div class="ui-tooltip" :class="[`ui-tooltip--${position}`]">
<slot />

<template
v-if="content || $refs['tooltip-content'] || $refs['tooltip-message']"
>
<template v-if="content || $refs['tooltip-content'] || $refs['tooltip-message']">
<div class="ui-tooltip__content-wrapper">
<slot name="tooltip-content">
<div class="ui-tooltip__content">
Expand Down
Loading

0 comments on commit e1b099a

Please sign in to comment.