Skip to content
Snippets Groups Projects
Commit 35b25960 authored by Ingrid Martinsheimen Egge's avatar Ingrid Martinsheimen Egge :cow2:
Browse files

api

parent 3b1f9f80
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
Pipeline #220720 failed
......@@ -105,15 +105,22 @@ export const API = {
},
/**
* Fetches all available foodpreference options
* Deletes account from the
* @param id
* @param token
* @returns {Promise<*>}
*/
getFoodpreferences: async () => {
return axios.get(`${import.meta.env.VITE_BACKEND_URL}/foodpreferences`)
deleteAccount: async (id, token) => {
return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/account/{id}`, {
headers: { Authorization: `Bearer ${token}` },
})
.then((response) => {
return response.data;
}).catch(() => {
throw new Error();
})
.catch(() => {
throw new Error("Account not found or not accessible");
});
},
/**
......@@ -128,38 +135,28 @@ export const API = {
});
},
/**
* Deletes account from the
* @param id
* @param token
* @returns {Promise<*>}
*/
deleteAccount: async (id, token) => {
return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/account/{id}`, {
headers: { Authorization: `Bearer ${token}` },
})
.then((response) => {
return response.data;
})
.catch(() => {
throw new Error("Account not found or not accessible");
});
updateProfile: async (id, request) => {
const authStore = useAuthStore();
if (!authStore.isLoggedIn) {
throw new Error();
}
},
return axios.put(`${import.meta.env.VITE_BACKEND_URL}/profile/${id}`,request, {
headers: { Authorization: `Bearer ${authStore.token}` },
updateProfile: async (id, token) => {
return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/profile/{id}`, {
headers: { Authorization: `Bearer ${token}` },
})
.then((response) => {
//authStore.setProfile(response.data)
return response.data;
})
.catch(() => {
throw new Error("Account not found or not accessible");
.catch((error) => {
throw new Error("Error when updating profile: " + error);
});
},
}
......@@ -118,7 +118,7 @@ export default {
computed: {
...mapStores(useAuthStore),
profile() {
const store = useAuthStore();
let store = useAuthStore();
this.currentProfile.name = store.profile.name;
this.currentProfile.isRestricted = store.profile.restricted;
this.currentProfile.image = store.profile.profileImageUrl;
......@@ -152,14 +152,23 @@ export default {
},
methods: {
saveUserSettings(){ //profilnavn, profilbilde, profilrestriksjoner
console.log(this.currentProfile.image)
alert("(Denne knappen gjør ingen ting) brukerinnstillinger lagret!")
const namee = this.currentProfile.name;
const isRestrictede = this.currentProfile.isRestricted;
const profileImageUrle = this.currentProfile.image;
API.updateProfile(
this.user.id,
this.profile.name,
this.profile.isRestricted,
this.profile.image,
);
this.profile.id,{
name:namee,
profileImageUrl: profileImageUrle,
restricted: isRestrictede,
}
).then((savedProfile)=>{
useAuthStore().setProfile(savedProfile);
}).catch((error)=> {
console.log(error)
})
},
chooseProfilePicture(){
alert("velgBilde")
......@@ -171,11 +180,6 @@ export default {
alert("(Denne knappen gjør ingen ting) konto oppdatert")
}
/*API.updateAccount(
this.user.id,
this.user.password,
token);*/
},
deleteAccount(){
if(this.deletionConfirmation===false){
......
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