FitTrackee/fittrackee_client_old/src/fitTrackeeApi/index.js

64 lines
1.3 KiB
JavaScript
Raw Normal View History

import { createApiRequest, formatUrl } from '../utils'
2018-04-29 18:23:46 +02:00
export default class FitTrackeeApi {
2019-01-18 19:34:38 +01:00
static getData(target, data = {}) {
const url = formatUrl(target, data)
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 = {
url: `${target}${
data.id ? `/${data.id}` : data.username ? `/${data.username}` : ''
}`,
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
}