From 86834a9046b23d4ab2e57ead51edb220f0065b94 Mon Sep 17 00:00:00 2001 From: Michael Shanks Date: Mon, 23 Mar 2020 14:26:38 +0000 Subject: [PATCH] prettier auto fix --- .../src/database/ModelDataTable/api.js | 85 +++++++++---------- 1 file changed, 42 insertions(+), 43 deletions(-) diff --git a/packages/builder/src/database/ModelDataTable/api.js b/packages/builder/src/database/ModelDataTable/api.js index 480fa98de5..278c8eda33 100644 --- a/packages/builder/src/database/ModelDataTable/api.js +++ b/packages/builder/src/database/ModelDataTable/api.js @@ -1,47 +1,46 @@ - import api from "../../builderStore/api"; - import { getNewRecord, getNewInstance } from "../../common/core" +import api from "../../builderStore/api" +import { getNewRecord, getNewInstance } from "../../common/core" - export async function createDatabase(appname, instanceName) { - const CREATE_DATABASE_URL = `/_builder/instance/_master/0/api/record/` - const database = getNewInstance(appname, instanceName); - const response = await api.post(CREATE_DATABASE_URL, database); - return await response.json() +export async function createDatabase(appname, instanceName) { + const CREATE_DATABASE_URL = `/_builder/instance/_master/0/api/record/` + const database = getNewInstance(appname, instanceName) + const response = await api.post(CREATE_DATABASE_URL, database) + return await response.json() +} + +export async function deleteRecord(record, { appname, instanceId }) { + const DELETE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record${record.key}` + const response = await api.delete(DELETE_RECORDS_URL) + return response +} + +export async function saveRecord(record, { appname, instanceId }) { + let recordBase = { ...record } + + // brand new record + if (record.collectionName) { + const collectionKey = `/${record.collectionName}` + recordBase = getNewRecord(recordBase, collectionKey) + recordBase = overwritePresentProperties(recordBase, record) } - export async function deleteRecord(record, { appname, instanceId }) { - const DELETE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record${record.key}` - const response = await api.delete(DELETE_RECORDS_URL); - return response; + const SAVE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record/` + const response = await api.post(SAVE_RECORDS_URL, recordBase) + return await response.json() +} + +export async function fetchDataForView(viewName, { appname, instanceId }) { + const FETCH_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/listRecords/${viewName}` + + const response = await api.get(FETCH_RECORDS_URL) + return await response.json() +} + +function overwritePresentProperties(baseObj, overwrites) { + const base = { ...baseObj } + + for (let key in base) { + if (overwrites[key]) base[key] = overwrites[key] } - - export async function saveRecord(record, { appname, instanceId }) { - let recordBase = { ...record } - - // brand new record - if (record.collectionName) { - const collectionKey = `/${record.collectionName}` - recordBase = getNewRecord(recordBase, collectionKey) - recordBase = overwritePresentProperties(recordBase, record) - } - - const SAVE_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/record/` - const response = await api.post(SAVE_RECORDS_URL, recordBase) - return await response.json() - } - - export async function fetchDataForView(viewName, { appname, instanceId }) { - const FETCH_RECORDS_URL = `/_builder/instance/${appname}/${instanceId}/api/listRecords/${viewName}`; - - const response = await api.get(FETCH_RECORDS_URL); - return await response.json(); - - } - - function overwritePresentProperties(baseObj, overwrites) { - const base = { ...baseObj } - - for (let key in base) { - if (overwrites[key]) base[key] = overwrites[key] - } - return base; - } \ No newline at end of file + return base +}