Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes and improvements #309

Merged
merged 16 commits into from
Sep 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend
116 changes: 87 additions & 29 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@tanstack/vue-query": "^5.51.21",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^10.11.0",
"@vueuse/core": "^11.1.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"core-js": "^3.38.0",
Expand Down Expand Up @@ -85,7 +85,7 @@
"storybook-dark-mode": "^4.0.2",
"tailwindcss": "^3.4.8",
"typescript": "^5.5.4",
"vite": "^5.4.2",
"vite": "^5.4.7",
"vite-svg-loader": "^5.1.0",
"vitest": "^2.0.5",
"vue-style-loader": "^4.1.3",
Expand Down
69 changes: 49 additions & 20 deletions src/api/transactions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { TransactionModel, endpointsTypes, TRANSACTION_TRANSFER_NATURE } from "shared-types";
import {
TransactionModel,
endpointsTypes,
TRANSACTION_TRANSFER_NATURE,
ACCOUNT_TYPES,
TRANSACTION_TYPES,
SORT_DIRECTIONS,
} from "shared-types";
import { api } from "@/api/_api";
import { fromSystemAmount, toSystemAmount } from "@/api/helpers";

Expand All @@ -11,21 +18,47 @@ export const formatTransactionResponse = (transaction: TransactionModel): Transa
commissionRate: fromSystemAmount(transaction.commissionRate),
});

export const formatTransactionPayload = <T>(transaction: T): T => {
const params = transaction;
const fieldsToPatch = ["amount", "destinationAmount"];
export const formatTransactionPayload = <
T extends endpointsTypes.CreateTransactionBody | endpointsTypes.UpdateTransactionBody,
>(
transaction: T,
): T => {
const params = { ...transaction };
const timeFieldsToPatch = ["time", "startDate", "endDate"];

fieldsToPatch.forEach((field) => {
timeFieldsToPatch.forEach((field) => {
if (params[field]) params[field] = new Date(params[field]).toISOString();
});

const amountFieldsToPatch = ["amount", "destinationAmount", "amountLte", "amountGte"];

amountFieldsToPatch.forEach((field) => {
if (params[field]) params[field] = toSystemAmount(Number(params[field]));
});

return params;
};

export const loadTransactions = async (
params: endpointsTypes.GetTransactionsQuery,
): Promise<endpointsTypes.GetTransactionsResponse> => {
const result = await api.get("/transactions", params);
export const loadTransactions = async (params: {
from: number;
limit?: number;
accountType?: ACCOUNT_TYPES;
transactionType?: TRANSACTION_TYPES;
accountIds?: number[];
sort?: SORT_DIRECTIONS;
includeUser?: boolean;
includeAccount?: boolean;
includeCategory?: boolean;
includeAll?: boolean;
nestedInclude?: boolean;
excludeTransfer?: boolean;
excludeRefunds?: boolean;
startDate?: string;
endDate?: string;
amountLte?: number;
amountGte?: number;
}): Promise<endpointsTypes.GetTransactionsResponse> => {
const result = await api.get("/transactions", formatTransactionPayload(params));

return result.map((item) => formatTransactionResponse(item));
};
Expand All @@ -45,17 +78,13 @@ export const loadTransactionsByTransferId = async (
};

export const createTransaction = async (params: endpointsTypes.CreateTransactionBody) => {
try {
const formattedParams = formatTransactionPayload({
transferNature: TRANSACTION_TRANSFER_NATURE.not_transfer,
note: "",
...params,
});

return api.post("/transactions", formattedParams);
} catch (e) {
throw new Error(e);
}
const formattedParams = formatTransactionPayload({
transferNature: TRANSACTION_TRANSFER_NATURE.not_transfer,
note: "",
...params,
});

return api.post("/transactions", formattedParams);
};

export const editTransaction = async ({
Expand Down
2 changes: 0 additions & 2 deletions src/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<main class="page">
<router-view />

<ui-modal />
<notifications-center />
</main>
</template>
Expand All @@ -13,7 +12,6 @@ import { storeToRefs } from "pinia";
import { useRouter } from "vue-router";
import { useRootStore, useAuthStore, useCurrenciesStore } from "@/stores";
import { ROUTES_NAMES } from "@/routes";
import UiModal from "@/components/modal-center/ui-modal.vue";

import NotificationsCenter from "@/components/notification-center/notifications-center.vue";

Expand Down
2 changes: 2 additions & 0 deletions src/common/const/vue-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const VUE_QUERY_CACHE_KEYS = Object.freeze({
accountSpecificTransactions: [TX_CHANGE_QUERY, "account-transactions"],

allAccounts: [TX_CHANGE_QUERY, "all-accounts"],

exchangeRates: ["exchange-rates"],
});

export { TX_CHANGE_QUERY as VUE_QUERY_TX_CHANGE_QUERY };
Loading
Loading