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

api

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