2020-03-31 13:16:03 +02:00
|
|
|
import api from "builderStore/api"
|
2020-03-23 15:26:38 +01:00
|
|
|
|
2020-06-19 18:19:30 +02:00
|
|
|
export async function createUser(user) {
|
2021-04-09 16:11:49 +02:00
|
|
|
const CREATE_USER_URL = `/api/users/metadata`
|
2020-04-23 15:37:08 +02:00
|
|
|
const response = await api.post(CREATE_USER_URL, user)
|
2020-05-14 16:12:30 +02:00
|
|
|
return await response.json()
|
2020-03-24 17:17:10 +01:00
|
|
|
}
|
|
|
|
|
2020-10-09 20:10:28 +02:00
|
|
|
export async function saveRow(row, tableId) {
|
2020-11-24 18:00:15 +01:00
|
|
|
const SAVE_ROW_URL = `/api/${tableId}/rows`
|
|
|
|
const response = await api.post(SAVE_ROW_URL, row)
|
2020-08-17 22:01:43 +02:00
|
|
|
|
2020-03-23 15:26:38 +01:00
|
|
|
return await response.json()
|
|
|
|
}
|
|
|
|
|
2020-10-09 20:10:28 +02:00
|
|
|
export async function deleteRow(row) {
|
2021-06-14 14:52:06 +02:00
|
|
|
const DELETE_ROWS_URL = `/api/${row.tableId}/rows`
|
|
|
|
return api.delete(DELETE_ROWS_URL, {
|
|
|
|
_id: row._id,
|
|
|
|
_rev: row._rev,
|
|
|
|
})
|
2020-03-27 12:28:30 +01:00
|
|
|
}
|
|
|
|
|
2021-06-15 14:32:11 +02:00
|
|
|
export async function fetchDataForTable(tableId) {
|
|
|
|
const FETCH_ROWS_URL = `/api/${tableId}/rows`
|
2020-03-12 15:23:29 +01:00
|
|
|
|
2020-10-09 20:10:28 +02:00
|
|
|
const response = await api.get(FETCH_ROWS_URL)
|
2020-12-18 19:19:43 +01:00
|
|
|
const json = await response.json()
|
|
|
|
|
|
|
|
if (response.status !== 200) {
|
|
|
|
throw new Error(json.message)
|
|
|
|
}
|
|
|
|
return json
|
|
|
|
}
|