Skip to content
Snippets Groups Projects
Commit 29c5f03e authored by Ingrid's avatar Ingrid
Browse files

la inn sletting av profil

parent 7606aada
No related branches found
No related tags found
1 merge request!21Merge profilinnstillinger into main
Pipeline #221989 failed
......@@ -16,10 +16,10 @@
<input type="text" required v-model="this.updatedProfile.upName"><br>
<br>
<h4>Brukertype</h4>
<input type="radio" id="normal" value="false" v-model="this.updatedProfile.upRestricted">
<input type="radio" id="normal" value="false" name="restrict" v-model="this.updatedProfile.upRestricted">
<label for="normal"> Standard</label><br>
<input type="radio" id="restricted" value="true" v-model="this.updatedProfile.upRestricted">
<input type="radio" id="restricted" value="true" name="restrict" v-model="this.updatedProfile.upRestricted">
<label for="restricted"> Begrenset - Kan ikke redigere ukeplan eller handleliste</label><br>
<br>
......@@ -39,7 +39,7 @@
<br><br>
<div id = "submitbuttonBox">
<button class="saveBtn" @click=" saveUserSettings">Lagre profilendringer</button>
<button class="delBtn" @click="deleteUser">Slett brukerprofil</button>
<button class="delBtn" @click="deleteProfile">Slett brukerprofil</button>
</div>
</form>
......@@ -73,34 +73,48 @@ export default {
return this.updatedProfile.upImage.length > 0;
}
},
data() {
return {
deletionConfirmation: false,
}
},
methods: {
saveUserSettings(){
const id = this.profile.id;
API.updateProfile(
id,{
const numOfProfiles = API.getProfiles().length
if(numOfProfiles===1 && this.updatedProfile.upRestricted===true){
alert("Du må ha minst en standardprofil per konto. (ingen endringer er gjort)")
}
else {
API.updateProfile(
id,{
name:this.updatedProfile.upName,
profileImageUrl:this.updatedProfile.upImage,
restricted:this.updatedProfile.upRestricted,
}
).then((savedProfile)=>{
}
).then((savedProfile)=>{
useAuthStore().setProfile(savedProfile);
alert("profil oppdatert.")
}).catch((error)=> {
}).catch((error)=> {
console.log(error)
})
})
}
},
chooseProfilePicture(){
alert("skriv inn bildelenke i feltet, og oppdater innstillinger")
},
changeProfile(){
router.push("/selectProfile");
}
},
deleteProfile(){
const numOfProfiles = API.getProfiles().length
if(numOfProfiles===1){
alert("Du kan ikke slette profilen. Hver Konto må ha minst en profil")
}else {
const id = this.profile.id;
API.deleteProfile(id).then(()=>{
router.push('/selectProfile')
}).catch((error)=> {
alert("Det oppsto en feil ved sletting profil: " + error)
})
}
}
}
}
......
......@@ -191,6 +191,32 @@ export const API = {
},
/**
* Deletes a profile from an account
* @param id
* @param request
* @returns {Promise<*>}
*/
deleteProfile: async (id) => {
const authStore = useAuthStore();
if (!authStore.isLoggedIn) {
throw new Error();
}
return axios.delete(`${import.meta.env.VITE_BACKEND_URL}/profile/${id}`, {
headers: { Authorization: `Bearer ${authStore.token}` },
})
.then(() => {
router.push('/selectProfile')
})
.catch(() => {
throw new Error("Kan ikke slette profil");
});
},
......
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