Skip to content
Snippets Groups Projects
Commit b5169723 authored by Henrik Teksle Sandok's avatar Henrik Teksle Sandok
Browse files

Merge branch 'refactor/Configuration' into 'main'

refactor/Added set bankaccounts details in configuration

See merge request !96
parents 05386be6 2e379d0b
No related branches found
No related tags found
1 merge request!96refactor/Added set bankaccounts details in configuration
Pipeline #284383 passed with warnings
...@@ -5,7 +5,7 @@ import BaseButton from '@/components/BaseComponents/Buttons/BaseButton.vue' ...@@ -5,7 +5,7 @@ import BaseButton from '@/components/BaseComponents/Buttons/BaseButton.vue'
import { ref } from 'vue' import { ref } from 'vue'
import { useConfigurationStore } from '@/stores/ConfigurationStore' import { useConfigurationStore } from '@/stores/ConfigurationStore'
import { useUserInfoStore } from '@/stores/UserStore' import { useUserInfoStore } from '@/stores/UserStore'
import { AuthenticationService, OpenAPI, type SignUpRequest } from '@/api' import { AuthenticationService, type BankAccountDTO, OpenAPI, type SignUpRequest, UserService } from '@/api'
import handleUnknownError from '@/components/Exceptions/unkownErrorHandler' import handleUnknownError from '@/components/Exceptions/unkownErrorHandler'
const router = useRouter(); const router = useRouter();
...@@ -49,50 +49,66 @@ const convertEnumToText = (enumValue: String) => { ...@@ -49,50 +49,66 @@ const convertEnumToText = (enumValue: String) => {
* @throws {Error} Throws an error if signup fails. * @throws {Error} Throws an error if signup fails.
*/ */
const signUpUser = async () => { const signUpUser = async () => {
try { // Saves the chosen challenges to the configuration store
// Saves the chosen challenges to the configuration store useConfigurationStore().setChallenges(chosenChallenges.value)
useConfigurationStore().setChallenges(chosenChallenges.value)
const signUpPayLoad: SignUpRequest = {
const signUpPayLoad: SignUpRequest = { firstName: useUserInfoStore().getFirstName,
firstName: useUserInfoStore().getFirstName, lastName: useUserInfoStore().getLastname,
lastName: useUserInfoStore().getLastname, email: useUserInfoStore().getEmail,
email: useUserInfoStore().getEmail, password: useUserInfoStore().getPassword,
password: useUserInfoStore().getPassword, configuration: {
configuration: { commitment: useConfigurationStore().getCommitment,
commitment: useConfigurationStore().getCommitment, experience: useConfigurationStore().getExperience,
experience: useConfigurationStore().getExperience, challengeTypes: useConfigurationStore().getChallenges
challengeTypes: useConfigurationStore().getChallenges
}
};
let response = await AuthenticationService.signup({ requestBody: signUpPayLoad });
if (response.token == null) {
errorMsg.value = 'A valid token could not be created';
return;
} }
OpenAPI.TOKEN = response.token; };
useUserInfoStore().setUserInfo({
accessToken: response.token, console.log(signUpPayLoad)
role: response.role,
}); let response = await AuthenticationService.signup({ requestBody: signUpPayLoad });
useUserInfoStore().resetPassword() if (response.token == null) {
await router.push("/first-saving-goal") errorMsg.value = 'A valid token could not be created';
return;
} }
catch (error) { OpenAPI.TOKEN = response.token;
errorMsg.value = handleUnknownError(error); useUserInfoStore().setUserInfo({
accessToken: response.token,
role: response.role,
});
}
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 = () => { const handleSubmit = async () => {
if (chosenChallenges.value.length === 0) { if (chosenChallenges.value.length === 0) {
chosenChallenges.value = challenges chosenChallenges.value = challenges
} }
useConfigurationStore().setChallenges(chosenChallenges.value) useConfigurationStore().setChallenges(chosenChallenges.value)
console.log(useConfigurationStore().getChallenges)
try { try {
signUpUser() await signUpUser();
} catch (e) { await updateBankAccounts();
console.log(e)
useUserInfoStore().resetPassword()
await router.push("/first-saving-goal")
} catch (error) {
errorMsg.value = handleUnknownError(error);
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment