From 17f456ea823afc78f5006e18323ae3302e5d11b4 Mon Sep 17 00:00:00 2001 From: heikkkk <henrik.teksle.sandok@hotmail.no> Date: Fri, 3 May 2024 18:45:12 +0200 Subject: [PATCH] fix: bank account --- .../ConfigurationSteps/BankAccount.vue | 22 ++++++++++++------ .../ConfigurationSteps/SuitableChallenges.vue | 23 ++++--------------- .../SavingGoal/SavingGoalRoadmap.vue | 4 ++-- src/stores/ConfigurationStore.ts | 20 ++++++++-------- 4 files changed, 31 insertions(+), 38 deletions(-) diff --git a/src/components/Configuration/ConfigurationSteps/BankAccount.vue b/src/components/Configuration/ConfigurationSteps/BankAccount.vue index e37709b..8e2256b 100644 --- a/src/components/Configuration/ConfigurationSteps/BankAccount.vue +++ b/src/components/Configuration/ConfigurationSteps/BankAccount.vue @@ -4,11 +4,13 @@ import BaseButton from '@/components/BaseComponents/Buttons/BaseButton.vue' import { ref } from 'vue' import BaseInput from '@/components/BaseComponents/Input/BaseInput.vue' import { useConfigurationStore } from '@/stores/ConfigurationStore' +import { AccountControllerService } from '@/api' +import handleUnknownError from '@/components/Exceptions/unkownErrorHandler' const router = useRouter(); const formRef = ref(); -const spendingAccount = ref<string>(''); +const checkingAccount = ref<string>(''); const savingsAccount = ref<string>(''); let errorMsg = ref(''); @@ -17,19 +19,25 @@ const emit = defineEmits(['changeRouterEvent']) emit('changeRouterEvent', '/bank-account') const handleSpendingInputEvent = (newValue: any) => { - spendingAccount.value = newValue + checkingAccount.value = newValue } const handleSavingInputEvent = (newValue: any) => { savingsAccount.value = newValue } -const handleSubmit = () => { +const handleSubmit = async () => { formRef.value.classList.add("was-validated") const form = formRef.value; if (form.checkValidity()) { - useConfigurationStore().setSpendingAccount(Number(spendingAccount.value)) - useConfigurationStore().setSavingsAccount(Number(savingsAccount.value)) - router.push("/commitment") + try { + await AccountControllerService.getAccountsByBban({bban: Number(checkingAccount.value)}) + await AccountControllerService.getAccountsByBban({bban: Number(savingsAccount.value)}) + useConfigurationStore().setChekingAccountBBAN(Number(checkingAccount.value)) + useConfigurationStore().setSavingsAccountBBAN(Number(savingsAccount.value)) + await router.push("/commitment") + } catch (error) { + errorMsg.value = handleUnknownError(error) + } } } </script> @@ -41,7 +49,7 @@ const handleSubmit = () => { </h3> <form ref="formRef"> <BaseInput data-cy="spending-account-input" - :model-value="spendingAccount" + :model-value="checkingAccount" @input-change-event="handleSpendingInputEvent" id="spending-account-base-input" input-id="spending-account-input" diff --git a/src/components/Configuration/ConfigurationSteps/SuitableChallenges.vue b/src/components/Configuration/ConfigurationSteps/SuitableChallenges.vue index 5dd4309..8d56476 100644 --- a/src/components/Configuration/ConfigurationSteps/SuitableChallenges.vue +++ b/src/components/Configuration/ConfigurationSteps/SuitableChallenges.vue @@ -5,7 +5,7 @@ import BaseButton from '@/components/BaseComponents/Buttons/BaseButton.vue' import { ref } from 'vue' import { useConfigurationStore } from '@/stores/ConfigurationStore' import { useUserInfoStore } from '@/stores/UserStore' -import { AuthenticationService, type BankAccountDTO, OpenAPI, type SignUpRequest, UserService } from '@/api' +import { AuthenticationService, OpenAPI, type SignUpRequest, UserService } from '@/api' import handleUnknownError from '@/components/Exceptions/unkownErrorHandler' const router = useRouter(); @@ -61,7 +61,9 @@ const signUpUser = async () => { commitment: useConfigurationStore().getCommitment, experience: useConfigurationStore().getExperience, challengeTypes: useConfigurationStore().getChallenges - } + }, + checkingAccountBBAN: useConfigurationStore().getCheckingAccountBBAN, + savingsAccountBBAN: useConfigurationStore().getSavingsAccountBBAN, }; console.log(signUpPayLoad) @@ -78,22 +80,6 @@ const signUpUser = async () => { }); } -const updateBankAccounts = async () => { - - const spendingRequest: BankAccountDTO = { - bban: useConfigurationStore().getSpendingAccount, - bankAccountType: "CHECKING_ACCOUNT" - } - - const savingRequest: BankAccountDTO = { - bban: useConfigurationStore().getSavingsAccount, - bankAccountType: "SAVING_ACCOUNT" - } - - await UserService.selectBankAccount({requestBody: spendingRequest}) - await UserService.selectBankAccount({requestBody: savingRequest}) -} - const handleSubmit = async () => { if (chosenChallenges.value.length === 0) { chosenChallenges.value = challenges @@ -102,7 +88,6 @@ const handleSubmit = async () => { try { await signUpUser(); - await updateBankAccounts(); useUserInfoStore().resetPassword() await router.push("/first-saving-goal") diff --git a/src/components/SavingGoal/SavingGoalRoadmap.vue b/src/components/SavingGoal/SavingGoalRoadmap.vue index c88ba1a..e9b4478 100644 --- a/src/components/SavingGoal/SavingGoalRoadmap.vue +++ b/src/components/SavingGoal/SavingGoalRoadmap.vue @@ -347,8 +347,8 @@ export default { async transferMoney(amount: number) { let response = await UserService.getUser() - let spendingAccount = response.checkingAccount?.bban - let savingAccount = response.savingsAccount?.bban + let spendingAccount = response.checkingAccountBBAN + let savingAccount = response.savingsAccountBBAN const transactionPayload: TransactionDTO = { debtorBBAN: spendingAccount, diff --git a/src/stores/ConfigurationStore.ts b/src/stores/ConfigurationStore.ts index 465edde..c1923a7 100644 --- a/src/stores/ConfigurationStore.ts +++ b/src/stores/ConfigurationStore.ts @@ -1,18 +1,18 @@ import { defineStore } from 'pinia' export const useConfigurationStore = defineStore('ConfigurationStore', { state: () => ({ - spendingAccount: 0, - savingsAccount: 0, + chekingAccountBBAN: 0, + savingsAccountBBAN: 0, commitment: '', experience: '', challenges: [] as Array<string>, }), actions: { - setSpendingAccount(newValue: number) { - this.spendingAccount = newValue; + setChekingAccountBBAN(newValue: number) { + this.chekingAccountBBAN = newValue; }, - setSavingsAccount(newValue: number) { - this.savingsAccount = newValue + setSavingsAccountBBAN(newValue: number) { + this.savingsAccountBBAN = newValue }, setCommitment(commitment: string) { this.commitment = commitment @@ -30,11 +30,11 @@ export const useConfigurationStore = defineStore('ConfigurationStore', { } }, getters: { - getSpendingAccount(): number { - return this.spendingAccount + getCheckingAccountBBAN(): number { + return this.chekingAccountBBAN }, - getSavingsAccount(): number { - return this.savingsAccount + getSavingsAccountBBAN(): number { + return this.savingsAccountBBAN }, getCommitment(): string { return this.commitment -- GitLab