2018-05-28 12:35:17 +02:00
|
|
|
import { apiUrl, createRequest } from '../utils'
|
2018-04-29 18:23:46 +02:00
|
|
|
|
2018-06-07 14:45:43 +02:00
|
|
|
export default class FitTrackeeApi {
|
2018-04-29 18:23:46 +02:00
|
|
|
|
2018-06-04 14:38:48 +02:00
|
|
|
static getData(target,
|
2018-06-04 14:55:09 +02:00
|
|
|
data = {}) {
|
2018-05-10 23:39:59 +02:00
|
|
|
let url = `${apiUrl}${target}`
|
2018-06-04 14:55:09 +02:00
|
|
|
if (data.id) {
|
|
|
|
url = `${url}/${data.id}`
|
2018-06-04 15:59:28 +02:00
|
|
|
} else if (Object.keys(data).length > 0) {
|
|
|
|
url = `${url}?${
|
|
|
|
data.page ? `&page=${data.page}` : ''
|
2018-06-06 20:17:37 +02:00
|
|
|
}${
|
2018-06-04 15:59:28 +02:00
|
|
|
data.start ? `&from=${data.start}` : ''
|
2018-06-06 20:17:37 +02:00
|
|
|
}${
|
2018-06-04 15:59:28 +02:00
|
|
|
data.end ? `&to=${data.end}` : ''
|
2018-06-06 20:17:37 +02:00
|
|
|
}${
|
2018-06-04 15:59:28 +02:00
|
|
|
data.order ? `&order=${data.order}` : ''
|
2018-06-06 20:17:37 +02:00
|
|
|
}${
|
2018-06-04 19:29:26 +02:00
|
|
|
data.per_page ? `&per_page=${data.per_page}` : ''
|
2018-06-06 20:17:37 +02:00
|
|
|
}`
|
2018-06-04 14:38:48 +02:00
|
|
|
}
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
|
|
|
url: url,
|
2018-04-29 18:23:46 +02:00
|
|
|
method: 'GET',
|
2018-05-28 12:35:17 +02:00
|
|
|
type: 'application/json',
|
|
|
|
}
|
|
|
|
return createRequest(params)
|
2018-04-29 18:23:46 +02:00
|
|
|
}
|
2018-04-30 20:08:18 +02:00
|
|
|
|
2018-04-30 21:38:09 +02:00
|
|
|
static addData(target, data) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
|
|
|
url: `${apiUrl}${target}`,
|
2018-04-30 21:38:09 +02:00
|
|
|
method: 'POST',
|
2018-05-28 12:35:17 +02:00
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
|
|
|
return createRequest(params)
|
2018-04-30 21:38:09 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 20:08:18 +02:00
|
|
|
static updateData(target, data) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
|
|
|
url: `${apiUrl}${target}/${data.id}`,
|
2018-04-30 20:08:18 +02:00
|
|
|
method: 'PATCH',
|
2018-05-28 12:35:17 +02:00
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
|
|
|
return createRequest(params)
|
2018-04-30 20:08:18 +02:00
|
|
|
}
|
2018-04-30 21:38:09 +02:00
|
|
|
|
|
|
|
static deleteData(target, id) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
|
|
|
url: `${apiUrl}${target}/${id}`,
|
2018-04-30 21:38:09 +02:00
|
|
|
method: 'DELETE',
|
2018-05-28 12:35:17 +02:00
|
|
|
type: 'application/json',
|
|
|
|
}
|
|
|
|
return createRequest(params)
|
2018-04-30 21:38:09 +02:00
|
|
|
}
|
2018-04-29 18:23:46 +02:00
|
|
|
}
|