2020-04-01 00:16:03 +13:00
|
|
|
import api from "builderStore/api"
|
2020-03-24 03:26:38 +13:00
|
|
|
|
2020-05-06 21:33:30 +12:00
|
|
|
export async function createUser(user, appId, instanceId) {
|
|
|
|
const CREATE_USER_URL = `/api/${appId}/${instanceId}/users`
|
2020-04-24 01:37:08 +12:00
|
|
|
const response = await api.post(CREATE_USER_URL, user)
|
|
|
|
const json = await response.json()
|
|
|
|
return json.user;
|
2020-03-25 05:17:10 +13:00
|
|
|
}
|
|
|
|
|
2020-04-24 01:37:08 +12:00
|
|
|
export async function createDatabase(clientId, appname, instanceName) {
|
|
|
|
const CREATE_DATABASE_URL = `/api/${clientId}/${appname}/instances`
|
|
|
|
const response = await api.post(CREATE_DATABASE_URL, {
|
|
|
|
name: instanceName
|
|
|
|
})
|
2020-03-24 03:26:38 +13:00
|
|
|
return await response.json()
|
|
|
|
}
|
|
|
|
|
2020-04-21 03:17:11 +12:00
|
|
|
export async function deleteRecord(record, instanceId) {
|
|
|
|
const DELETE_RECORDS_URL = `/api/${instanceId}/records/${record._id}/${record._rev}`
|
2020-03-24 03:26:38 +13:00
|
|
|
const response = await api.delete(DELETE_RECORDS_URL)
|
|
|
|
return response
|
2020-03-28 00:28:30 +13:00
|
|
|
}
|
|
|
|
|
2020-05-06 21:33:30 +12:00
|
|
|
// export async function loadRecord(key, { appname, instanceId }) {
|
|
|
|
// const LOAD_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record${key}`
|
|
|
|
// const response = await api.get(LOAD_RECORDS_URL)
|
|
|
|
// return await response.json()
|
|
|
|
// }
|
2020-03-24 03:26:38 +13:00
|
|
|
|
2020-04-25 05:02:51 +12:00
|
|
|
export async function saveRecord(record, instanceId) {
|
|
|
|
const SAVE_RECORDS_URL = `/api/${instanceId}/records`
|
2020-04-21 03:17:11 +12:00
|
|
|
const response = await api.post(SAVE_RECORDS_URL, record)
|
2020-04-29 01:39:35 +12:00
|
|
|
|
2020-03-24 03:26:38 +13:00
|
|
|
return await response.json()
|
|
|
|
}
|
2020-03-21 07:47:01 +13:00
|
|
|
|
2020-04-21 03:17:11 +12:00
|
|
|
export async function fetchDataForView(viewName, instanceId) {
|
|
|
|
const FETCH_RECORDS_URL = `/api/${instanceId}/${viewName}/records`
|
2020-03-13 03:23:29 +13:00
|
|
|
|
2020-03-24 03:26:38 +13:00
|
|
|
const response = await api.get(FETCH_RECORDS_URL)
|
|
|
|
return await response.json()
|
2020-04-21 03:17:11 +12:00
|
|
|
}
|