2020-03-12 15:23:29 +01:00
|
|
|
import api from "../../builderStore/api";
|
2020-03-16 19:54:48 +01:00
|
|
|
import { getNewRecord } from "../../common/core"
|
2020-03-12 15:23:29 +01:00
|
|
|
|
2020-03-16 19:54:48 +01:00
|
|
|
export async function deleteRecord(record, { appname, instanceId }) {
|
|
|
|
const DELETE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record/${record.name}/${record.id}`
|
2020-03-12 15:23:29 +01:00
|
|
|
const response = await api.delete({
|
|
|
|
url: DELETE_RECORDS_URL
|
|
|
|
});
|
2020-03-16 19:54:48 +01:00
|
|
|
return response;
|
2020-03-12 15:23:29 +01:00
|
|
|
}
|
|
|
|
|
2020-03-16 19:54:48 +01:00
|
|
|
export async function saveRecord(record, { appname, instanceId }) {
|
|
|
|
const SAVE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record`
|
|
|
|
const updatedRecord = getNewRecord(record, "")
|
|
|
|
const response = await api.post(SAVE_RECORDS_URL, updatedRecord)
|
|
|
|
return response
|
2020-03-12 15:23:29 +01:00
|
|
|
}
|
|
|
|
|
2020-03-16 19:54:48 +01:00
|
|
|
export async function fetchDataForView(viewName, { appname, instanceId }) {
|
|
|
|
const FETCH_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/listRecords/${viewName}`;
|
2020-03-12 15:23:29 +01:00
|
|
|
|
2020-03-16 19:54:48 +01:00
|
|
|
// TODO: Error handling
|
|
|
|
const response = await api.get(FETCH_RECORDS_URL);
|
|
|
|
return await response.json();
|
2020-03-12 15:23:29 +01:00
|
|
|
|
|
|
|
}
|