FitTrackee/mpwo_client/src/mwpoApi/index.js

66 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-05-28 12:35:17 +02:00
import { apiUrl, createRequest } from '../utils'
2018-04-29 18:23:46 +02:00
export default class MpwoApi {
static getData(target,
id = null,
page = null,
start = null,
end = null,
order = null) {
let url = `${apiUrl}${target}`
if (id) {
url = `${url}/${id}`
} else if (page) {
url = `${url}?page=${page}`
}
if (start || end) {
url = `${url}${
page ? '' : '?'
}${
start && `&from=${start}`
}${
end && `&to=${end}`
}`
}
if (order) {
url = `${url}${(page || start || end) ? '' : '?'}${`&order=${order}`}`
}
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
}