Skip to content

Commit

Permalink
Merge pull request #309 from letehaha/fix/minor-issues
Browse files Browse the repository at this point in the history
Minor fixes and improvements
  • Loading branch information
letehaha authored Sep 22, 2024
2 parents 0ee4a17 + 4eee813 commit 286f91c
Show file tree
Hide file tree
Showing 82 changed files with 1,985 additions and 781 deletions.
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

0 comments on commit 286f91c

Please sign in to comment.