FitTrackee/mpwo_client/src/mpwoApi.js

96 lines
2.7 KiB
JavaScript
Raw Normal View History

2018-01-14 14:41:03 +01:00
const apiUrl = `${process.env.REACT_APP_API_URL}/api/`
export default class MpwoApi {
static login(email, password) {
const request = new Request(`${apiUrl}auth/login`, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
}),
body: JSON.stringify({
email: email,
password: password,
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
2018-01-01 11:10:39 +01:00
static register(username, email, password, passwordConf) {
const request = new Request(`${apiUrl}auth/register`, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
}),
body: JSON.stringify({
username: username,
email: email,
password: password,
2018-01-01 11:10:39 +01:00
password_conf: passwordConf,
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
static getProfile() {
const request = new Request(`${apiUrl}auth/profile`, {
method: 'GET',
headers: new Headers({
'Content-Type': 'application/json',
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
2018-01-01 16:59:46 +01:00
static updateProfile(form) {
const request = new Request(`${apiUrl}auth/profile/edit`, {
method: 'POST',
headers: new Headers({
'Content-Type': 'application/json',
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
body: JSON.stringify({
first_name: form.firstName,
last_name: form.lastName,
bio: form.bio,
location: form.location,
2018-01-01 17:50:12 +01:00
birth_date: form.birthDate,
password: form.password,
password_conf: form.passwordConf,
2018-01-01 16:59:46 +01:00
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
2018-01-01 21:54:03 +01:00
static updatePicture(form) {
const request = new Request(`${apiUrl}auth/picture`, {
method: 'POST',
headers: new Headers({
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
body: form,
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
static deletePicture() {
const request = new Request(`${apiUrl}auth/picture`, {
method: 'DELETE',
headers: new Headers({
Authorization: `Bearer ${window.localStorage.getItem('authToken')}`,
}),
})
return fetch(request)
.then(response => response.json())
.catch(error => error)
}
static getApiUrl() {
return apiUrl
}
}