From 4950db460c75e99d23ec0d1ee43641084f627c7e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 14 Jun 2021 19:07:13 +0100 Subject: [PATCH] Formatting. --- .../TableIntegrationMenu/index.svelte | 2 +- .../modals/CreateDatasourceModal.svelte | 2 +- packages/client/src/api/rows.js | 2 +- .../src/api/controllers/row/external.js | 60 ++++++++++++------- .../server/src/api/controllers/row/index.js | 6 +- .../src/api/controllers/row/internal.js | 12 ++-- packages/server/src/constants/index.js | 1 - packages/server/src/integrations/base/sql.js | 9 +-- .../src/integrations/microsoftSqlServer.js | 1 - packages/server/src/integrations/postgres.js | 1 - 10 files changed, 51 insertions(+), 45 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/index.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/index.svelte index 56336c5335..4a9bd66367 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/index.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/index.svelte @@ -29,7 +29,7 @@ integration = { type: integrationType, plus: selected.plus, - ...schema + ...schema, } } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte index daf2127960..180d03f7ff 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/modals/CreateDatasourceModal.svelte @@ -30,7 +30,7 @@ name, source: type, config, - plus + plus, }) notifications.success(`Datasource ${name} created successfully.`) analytics.captureEvent("Datasource Created", { name, type }) diff --git a/packages/client/src/api/rows.js b/packages/client/src/api/rows.js index 76bd5c214b..14d696351d 100644 --- a/packages/client/src/api/rows.js +++ b/packages/client/src/api/rows.js @@ -69,7 +69,7 @@ export const deleteRow = async ({ tableId, rowId, revId }) => { body: { _id: rowId, _rev: revId, - } + }, }) res.error ? notificationStore.danger("An error has occurred") diff --git a/packages/server/src/api/controllers/row/external.js b/packages/server/src/api/controllers/row/external.js index 11c11bf9bd..d958c75e45 100644 --- a/packages/server/src/api/controllers/row/external.js +++ b/packages/server/src/api/controllers/row/external.js @@ -10,11 +10,16 @@ async function buildIDFilter(id) { return { equal: { id: id, - } + }, } } -async function handleRequest(appId, operation, tableId, { id, row, filters, sort, paginate }) { +async function handleRequest( + appId, + operation, + tableId, + { id, row, filters, sort, paginate } +) { let [datasourceId, tableName] = tableId.split("/") let idFilter = buildIDFilter(id) let json = { @@ -34,49 +39,56 @@ async function handleRequest(appId, operation, tableId, { id, row, filters, sort return makeExternalQuery(appId, json) } -exports.patch = async (ctx) => { +exports.patch = async ctx => { const appId = ctx.appId const inputs = ctx.request.body const tableId = ctx.params.tableId const id = inputs._id // don't save the ID to db delete inputs._id - ctx.body = await handleRequest(appId, DataSourceOperation.UPDATE, tableId, { id, row: inputs }) + ctx.body = await handleRequest(appId, DataSourceOperation.UPDATE, tableId, { + id, + row: inputs, + }) } -exports.save = async (ctx) => { +exports.save = async ctx => { const appId = ctx.appId const inputs = ctx.request.body if (inputs._id) { return exports.patch(ctx) } const tableId = ctx.params.tableId - ctx.body = await handleRequest(appId, DataSourceOperation.CREATE, tableId, { row: inputs }) + ctx.body = await handleRequest(appId, DataSourceOperation.CREATE, tableId, { + row: inputs, + }) } -exports.fetchView = async (ctx) => { +exports.fetchView = async ctx => { // TODO: don't know what this does for external } -exports.fetchTableRows = async (ctx) => { +exports.fetchTableRows = async ctx => { // TODO: this is a basic read? } -exports.find = async (ctx) => { +exports.find = async ctx => { // TODO: single find } -exports.destroy = async (ctx) => { +exports.destroy = async ctx => { const appId = ctx.appId const tableId = ctx.params.tableId - ctx.body = await handleRequest(appId, DataSourceOperation.DELETE, tableId, { id: ctx.request.body._id }) + ctx.body = await handleRequest(appId, DataSourceOperation.DELETE, tableId, { + id: ctx.request.body._id, + }) } -exports.bulkDestroy = async (ctx) => { +exports.bulkDestroy = async ctx => { // TODO: iterate through rows, build a large OR filter? } -exports.search = async (ctx) => { +exports.search = async ctx => { const appId = ctx.appId const tableId = ctx.params.tableId const { paginate, query, ...params } = ctx.request.body @@ -90,25 +102,27 @@ exports.search = async (ctx) => { } let sort if (params.sort) { + const direction = + params.sortOrder === "descending" + ? SortDirection.DESCENDING + : SortDirection.ASCENDING sort = { - [params.sort]: params.sortOrder === "descending" ? SortDirection.DESCENDING : SortDirection.ASCENDING + [params.sort]: direction, } } - ctx.body = await handleRequest(appId, DataSourceOperation.READ, tableId, - { - filters: query, - sort, - paginate: paginateObj, - } - ) + ctx.body = await handleRequest(appId, DataSourceOperation.READ, tableId, { + filters: query, + sort, + paginate: paginateObj, + }) } -exports.validate = async (ctx) => { +exports.validate = async ctx => { // can't validate external right now - maybe in future ctx.body = { valid: true } } -exports.fetchEnrichedRow = async (ctx) => { +exports.fetchEnrichedRow = async ctx => { // TODO: should this join? const appId = ctx.appId ctx.body = {} diff --git a/packages/server/src/api/controllers/row/index.js b/packages/server/src/api/controllers/row/index.js index c077a69705..6eaac88119 100644 --- a/packages/server/src/api/controllers/row/index.js +++ b/packages/server/src/api/controllers/row/index.js @@ -23,7 +23,8 @@ exports.patch = async ctx => { const tableId = getTableId(ctx) try { const { row, table } = await pickApi(tableId).patch(ctx) - ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table) + ctx.eventEmitter && + ctx.eventEmitter.emitRow(`row:update`, appId, row, table) ctx.message = `${table.name} updated successfully` ctx.body = row } catch (err) { @@ -104,7 +105,6 @@ exports.search = async ctx => { } } - exports.validate = async function (ctx) { const tableId = getTableId(ctx) try { @@ -121,4 +121,4 @@ exports.fetchEnrichedRow = async function (ctx) { } catch (err) { ctx.throw(400, err) } -} \ No newline at end of file +} diff --git a/packages/server/src/api/controllers/row/internal.js b/packages/server/src/api/controllers/row/internal.js index cfe785058d..5982259eec 100644 --- a/packages/server/src/api/controllers/row/internal.js +++ b/packages/server/src/api/controllers/row/internal.js @@ -135,7 +135,7 @@ exports.save = async function (ctx) { return { row, table } } -exports.fetchView = async (ctx) => { +exports.fetchView = async ctx => { const appId = ctx.appId const viewName = ctx.params.viewName @@ -195,7 +195,7 @@ exports.fetchView = async (ctx) => { return rows } -exports.fetchTableRows = async (ctx) => { +exports.fetchTableRows = async ctx => { const appId = ctx.appId const db = new CouchDB(appId) @@ -215,7 +215,7 @@ exports.fetchTableRows = async (ctx) => { return outputProcessing(appId, table, rows) } -exports.find = async (ctx) => { +exports.find = async ctx => { const appId = ctx.appId const db = new CouchDB(appId) const table = await db.get(ctx.params.tableId) @@ -246,7 +246,7 @@ exports.destroy = async function (ctx) { await userController.destroyMetadata(ctx) return { response: ctx.body, row } } else { - const response = await db.remove(_id, _rev) + const response = await db.remove(_id, _rev) return { response, row } } } @@ -304,7 +304,7 @@ exports.search = async ctx => { ctx.body = response } -exports.validate = async (ctx) => { +exports.validate = async ctx => { return validate({ appId: ctx.appId, tableId: ctx.params.tableId, @@ -312,7 +312,7 @@ exports.validate = async (ctx) => { }) } -exports.fetchEnrichedRow = async (ctx) => { +exports.fetchEnrichedRow = async ctx => { const appId = ctx.appId const db = new CouchDB(appId) const tableId = ctx.params.tableId diff --git a/packages/server/src/constants/index.js b/packages/server/src/constants/index.js index ced7577de8..b01aa0d994 100644 --- a/packages/server/src/constants/index.js +++ b/packages/server/src/constants/index.js @@ -43,7 +43,6 @@ exports.SortDirection = { DESCENDING: "DESCENDING", } - exports.USERS_TABLE_SCHEMA = { _id: "ta_users", type: "table", diff --git a/packages/server/src/integrations/base/sql.js b/packages/server/src/integrations/base/sql.js index dfaa8ea11f..b22ea50bc3 100644 --- a/packages/server/src/integrations/base/sql.js +++ b/packages/server/src/integrations/base/sql.js @@ -1,7 +1,4 @@ -const { - DataSourceOperation, - SortDirection, -} = require("../../constants") +const { DataSourceOperation, SortDirection } = require("../../constants") const BASE_LIMIT = 5000 @@ -50,9 +47,7 @@ function addFilters(query, filters) { return query } -function buildRelationships() { - -} +function buildRelationships() {} function buildCreate(knex, json) { const { endpoint, body } = json diff --git a/packages/server/src/integrations/microsoftSqlServer.js b/packages/server/src/integrations/microsoftSqlServer.js index 8228006b5d..9e5203548f 100644 --- a/packages/server/src/integrations/microsoftSqlServer.js +++ b/packages/server/src/integrations/microsoftSqlServer.js @@ -59,7 +59,6 @@ async function internalQuery(client, sql) { } } - class SqlServerIntegration extends Sql { static pool diff --git a/packages/server/src/integrations/postgres.js b/packages/server/src/integrations/postgres.js index 5596e78b63..72b02431be 100644 --- a/packages/server/src/integrations/postgres.js +++ b/packages/server/src/integrations/postgres.js @@ -63,7 +63,6 @@ async function internalQuery(client, sql) { } } - class PostgresIntegration extends Sql { static pool