From 0cf612029e63d4a8c1e3750dd587b20c939122e1 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 12 Nov 2021 19:39:12 +0000 Subject: [PATCH] Linting and updating csv parser test case to match new functionality. --- .../server/src/api/controllers/row/ExternalRequest.ts | 5 ++++- packages/server/src/integrations/base/sqlTable.ts | 5 +---- packages/server/src/integrations/postgres.ts | 10 +++++----- packages/server/src/utilities/csvParser.js | 4 +++- .../tests/__snapshots__/csvParser.spec.js.snap | 6 ------ packages/server/src/utilities/tests/csvParser.spec.js | 3 +++ 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 02748f9f90..95710cd688 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -601,7 +601,10 @@ module External { throw `Unable to process query, table "${tableName}" not defined.` } // look for specific components of config which may not be considered acceptable - let { id, row, filters, sort, paginate, rows } = cleanupConfig(config, table) + let { id, row, filters, sort, paginate, rows } = cleanupConfig( + config, + table + ) filters = buildFilters(id, filters || {}, table) const relationships = this.buildRelationships(table) // clean up row on ingress using schema diff --git a/packages/server/src/integrations/base/sqlTable.ts b/packages/server/src/integrations/base/sqlTable.ts index 509af00955..53d123e38b 100644 --- a/packages/server/src/integrations/base/sqlTable.ts +++ b/packages/server/src/integrations/base/sqlTable.ts @@ -29,10 +29,7 @@ function generateSchema( for (let [key, column] of Object.entries(table.schema)) { // skip things that are already correct const oldColumn = oldTable ? oldTable.schema[key] : null - if ( - (oldColumn && oldColumn.type) || - (primaryKey === key && !isJunction) - ) { + if ((oldColumn && oldColumn.type) || (primaryKey === key && !isJunction)) { continue } switch (column.type) { diff --git a/packages/server/src/integrations/postgres.ts b/packages/server/src/integrations/postgres.ts index e42681873d..b2e48ad540 100644 --- a/packages/server/src/integrations/postgres.ts +++ b/packages/server/src/integrations/postgres.ts @@ -130,7 +130,7 @@ module PostgresModule { public tables: Record = {} public schemaErrors: Record = {} - COLUMNS_SQL!: string + COLUMNS_SQL!: string PRIMARY_KEYS_SQL = ` select tc.table_schema, tc.table_name, kc.column_name as primary_key @@ -165,11 +165,11 @@ module PostgresModule { setSchema() { if (!this.config.schema) { - this.config.schema = 'public' + this.config.schema = "public" } - this.client.on('connect', (client: any) => { - client.query(`SET search_path TO ${this.config.schema}`); - }); + this.client.on("connect", (client: any) => { + client.query(`SET search_path TO ${this.config.schema}`) + }) this.COLUMNS_SQL = `select * from information_schema.columns where table_schema = '${this.config.schema}'` } diff --git a/packages/server/src/utilities/csvParser.js b/packages/server/src/utilities/csvParser.js index 7a0d46a58c..323c077315 100644 --- a/packages/server/src/utilities/csvParser.js +++ b/packages/server/src/utilities/csvParser.js @@ -95,7 +95,9 @@ async function transform({ schema, csvString, existingTable }) { const colParser = {} // make sure the table has all the columns required for import - schema = updateSchema({ schema, existingTable }) + if (existingTable) { + schema = updateSchema({ schema, existingTable }) + } for (let key of Object.keys(schema)) { colParser[key] = PARSERS[schema[key].type] || schema[key].type diff --git a/packages/server/src/utilities/tests/__snapshots__/csvParser.spec.js.snap b/packages/server/src/utilities/tests/__snapshots__/csvParser.spec.js.snap index 3c532413fa..07f73ba2ef 100644 --- a/packages/server/src/utilities/tests/__snapshots__/csvParser.spec.js.snap +++ b/packages/server/src/utilities/tests/__snapshots__/csvParser.spec.js.snap @@ -3,19 +3,13 @@ exports[`CSV Parser transformation transforms a CSV file into JSON 1`] = ` Array [ Object { - "Address": "5 Sesame Street", "Age": 4324, - "Name": "Bertå", }, Object { - "Address": "1 World Trade Center", "Age": 34, - "Name": "Ernie", }, Object { - "Address": "44 Second Avenue", "Age": 23423, - "Name": "Big Bird", }, ] `; diff --git a/packages/server/src/utilities/tests/csvParser.spec.js b/packages/server/src/utilities/tests/csvParser.spec.js index 76ea9a7eb3..2a997e6f3a 100644 --- a/packages/server/src/utilities/tests/csvParser.spec.js +++ b/packages/server/src/utilities/tests/csvParser.spec.js @@ -24,6 +24,9 @@ const SCHEMAS = { Age: { type: "omit", }, + Name: { + type: "string", + }, }, BROKEN: { Address: {