2019-02-26 01:17:52 +01:00
|
|
|
import axios from 'axios'
|
|
|
|
|
import store from './store'
|
|
|
|
|
const api = axios.create({
|
2019-03-05 15:17:12 +01:00
|
|
|
baseURL: process.env.NODE_ENV === 'development' ? 'http://localhost:9000/api' : '/api',
|
2019-02-26 01:17:52 +01:00
|
|
|
withCredentials: false,
|
|
|
|
|
responseType: 'json',
|
|
|
|
|
headers: {
|
|
|
|
|
'Accept': 'application/json',
|
|
|
|
|
'Content-Type': 'application/json'
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function get (path) {
|
2019-03-05 15:17:12 +01:00
|
|
|
return api.get(path, { headers: { 'x-access-token': store.state.token } })
|
|
|
|
|
.then(res => res.data)
|
|
|
|
|
.catch(e => {
|
|
|
|
|
if (e.response.status === 403) {
|
|
|
|
|
store.commit('logout')
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-02-26 01:17:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function post (path, data) {
|
2019-03-05 15:17:12 +01:00
|
|
|
return api.post(path, data, { headers: { 'x-access-token': store.state.token } })
|
|
|
|
|
.then(res => res.data)
|
|
|
|
|
.catch(e => {
|
|
|
|
|
if (e.response.status === 403) {
|
|
|
|
|
store.commit('logout')
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
})
|
2019-02-26 01:17:52 +01:00
|
|
|
}
|
|
|
|
|
function put (path, data) {
|
2019-03-05 15:17:12 +01:00
|
|
|
return api.put(path, data, { headers: { 'x-access-token': store.state.token } })
|
|
|
|
|
.then(ret => ret.data)
|
2019-02-26 01:17:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function del (path) {
|
|
|
|
|
return api.delete(path, { headers: { 'x-access-token': store.state.token } }).then(ret => ret.data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
login: (email, password) => post('/login', { email, password }),
|
|
|
|
|
register: user => post('/user', user),
|
|
|
|
|
getAllEvents: (month, year) => get(`/event/${year}/${month}/`),
|
|
|
|
|
addEvent: event => post('/user/event', event),
|
|
|
|
|
updateEvent: event => put('/user/event', event),
|
2019-03-03 01:04:24 +01:00
|
|
|
updatePlace: place => put('/place', place),
|
2019-02-26 01:17:52 +01:00
|
|
|
delEvent: eventId => del(`/user/event/${eventId}`),
|
|
|
|
|
getEvent: eventId => get(`/event/${eventId}`),
|
|
|
|
|
getMeta: () => get('/event/meta'),
|
|
|
|
|
getUser: () => get('/user'),
|
|
|
|
|
getUsers: () => get('/users'),
|
|
|
|
|
updateTag: (tag) => put('/tag', tag),
|
|
|
|
|
updateUser: user => put('/user', user),
|
|
|
|
|
getAuthURL: mastodonInstance => post('/user/getauthurl', mastodonInstance),
|
|
|
|
|
setCode: code => post('/user/code', code),
|
|
|
|
|
getKnowLocations: () => get('/locations'),
|
|
|
|
|
getKnowTags: () => get('/tags')
|
|
|
|
|
}
|