Skip to content
Snippets Groups Projects
Commit 6c058628 authored by Jakob Grønhaug's avatar Jakob Grønhaug
Browse files

Merge branch 'opprett-profil' of...

Merge branch 'opprett-profil' of gitlab.stud.idi.ntnu.no:idatt2106-scrum-team-02/frontend into opprett-profil
parents 9bcdc0df 0b841795
No related branches found
No related tags found
1 merge request!15all funksjonalitet og filopplasting på plass
Pipeline #224183 passed
......@@ -78,16 +78,41 @@ export const API = {
.catch(() => {
throw new Error("Profile not found or not accessible")
})
},
/**
* Upload profile image
*
* @param {Blob} image - the image file contents to upload. Must be a JPEG no bigger than 512kB
* @param {Number} profileId - the ID of the profile to upload this image to
* @returns {Promise<String>} A Promise that resolves to the URL of the uploaded image
*/
uploadProfileImage: async (image, profileId) => {
const authStore = useAuthStore();
let fd = new FormData();
fd.append("file", image);
fd.append("profileId", profileId);
return axios.post(`${import.meta.env.VITE_BACKEND_URL}/img`, fd, {
headers: {
Authorization: `Bearer ${authStore.token}`,
}
})
.then((response) => {
return response.data;
})
.catch(() => {
throw new Error();
})
},
/**
* Sends a request to create a new profile on the currently logged in account
*
* @typedef {{name: string, profileImageUrl: string, isRestricted: boolean}} ProfileType
* @param {ProfileType} profile
* @returns
* @typedef {{name: string, id?: number, accountId?: number, profileImageUrl: string, isRestricted: boolean}} ProfileType
* @param {ProfileType} profile - the partial data of profile to create
* @returns {Promise<ProfileType>} the full profile after saving, with id and account ID set
*/
addProfile: async (profile) => {
const authStore = useAuthStore();
......@@ -95,9 +120,8 @@ export const API = {
throw new Error();
}
return axios.post(import.meta.env.VITE_BACKEND_URL + '/profile', {
return axios.post(import.meta.env.VITE_BACKEND_URL + '/profile', profile, {
headers: { Authorization: "Bearer " + authStore.token },
body: profile
})
.then((response) => {
return response.data;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment