diff --git a/src/components/Configuration/ConfigurationSteps/BankAccount.vue b/src/components/Configuration/ConfigurationSteps/BankAccount.vue index e37709b89e5681de22914d80683993007bc4838c..8e2256bbb945a77a8730a2905f26efa7728cb2fd 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 5dd43090895f0efc6992771b6c4369a56f9a2683..8d56476be08e5a2112c9e7d804d33acac0c1d988 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 c88ba1a6c69f41b0da02c87f59e3cc62ab9e9331..e9b447889bc0ced5921228c9556ab6e20418c864 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 465edde65849684c603a94dc25225fe6f037743a..c1923a7d0fe703b0b787407589605ae42ff6a4ba 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