2019-01-18 19:34:38 +01:00
|
|
|
import { createApiRequest } from '../utils'
|
2018-04-29 18:23:46 +02:00
|
|
|
|
2018-06-07 14:45:43 +02:00
|
|
|
export default class FitTrackeeApi {
|
2019-01-18 19:34:38 +01:00
|
|
|
static getData(target, data = {}) {
|
|
|
|
let url = 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) {
|
2018-06-07 19:28:06 +02:00
|
|
|
url += '?'
|
2019-08-28 15:35:22 +02:00
|
|
|
Object.keys(data).map(key => (url += `&${key}=${data[key]}`))
|
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',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(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 = {
|
2019-01-18 19:34:38 +01:00
|
|
|
url: target,
|
2018-04-30 21:38:09 +02:00
|
|
|
method: 'POST',
|
2018-05-28 12:35:17 +02:00
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-04-30 21:38:09 +02:00
|
|
|
}
|
|
|
|
|
2018-06-12 12:51:23 +02:00
|
|
|
static addDataWithFile(target, data) {
|
|
|
|
const params = {
|
2019-01-18 19:34:38 +01:00
|
|
|
url: target,
|
2018-06-12 12:51:23 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: data,
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-06-12 12:51:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static postData(target, data) {
|
|
|
|
const params = {
|
2019-08-28 15:35:22 +02:00
|
|
|
url: `${target}${data.id ? `/${data.id}` : ''}`,
|
2018-06-12 12:51:23 +02:00
|
|
|
method: 'POST',
|
|
|
|
body: data,
|
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-06-12 12:51:23 +02:00
|
|
|
}
|
|
|
|
|
2018-04-30 20:08:18 +02:00
|
|
|
static updateData(target, data) {
|
2018-05-28 12:35:17 +02:00
|
|
|
const params = {
|
2019-11-13 20:15:50 +01:00
|
|
|
url: `${target}${data.id ? `/${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',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(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 = {
|
2019-01-18 19:34:38 +01:00
|
|
|
url: `${target}/${id}`,
|
2018-04-30 21:38:09 +02:00
|
|
|
method: 'DELETE',
|
2018-05-28 12:35:17 +02:00
|
|
|
type: 'application/json',
|
|
|
|
}
|
2019-01-18 19:34:38 +01:00
|
|
|
return createApiRequest(params)
|
2018-04-30 21:38:09 +02:00
|
|
|
}
|
2018-04-29 18:23:46 +02:00
|
|
|
}
|