From 73f54c8133d2dbff7856f4dd1ae8372193ef7b55 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 27 Oct 2022 16:28:26 +0100 Subject: [PATCH 1/5] Decode id if needed --- packages/server/src/api/controllers/row/ExternalRequest.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index dc62453f77..0af6ed12af 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -282,8 +282,12 @@ module External { const linkTablePrimary = linkTable.primary[0] // one to many if (isOneSide(field)) { + let id = row[key][0] + if (isNaN(id)) { + id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1] + } newRow[field.foreignKey || linkTablePrimary] = breakRowIdField( - row[key][0] + id )[0] } // many to many From ee6a5bffd592f6a35ea03d3b0f1b8a257ca83cad Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 27 Oct 2022 17:52:28 +0100 Subject: [PATCH 2/5] Patch: Throw 404 if row not found --- packages/server/src/api/controllers/row/ExternalRequest.ts | 4 +--- packages/server/src/api/controllers/row/index.ts | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 0af6ed12af..4463dabd5a 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -286,9 +286,7 @@ module External { if (isNaN(id)) { id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1] } - newRow[field.foreignKey || linkTablePrimary] = breakRowIdField( - id - )[0] + newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0] } // many to many else if (field.through) { diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index 901589970b..55af998759 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -37,6 +37,9 @@ export async function patch(ctx: any): Promise { datasourceId: tableId, } ) + if (!row) { + ctx.throw(404, "Row not found!") + } ctx.status = 200 ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:update`, appId, row, table) From ea34856896e327555e186a8569ba8aaf78a15253 Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Thu, 27 Oct 2022 17:55:46 +0100 Subject: [PATCH 3/5] Check for string type before decode --- packages/server/src/api/controllers/row/ExternalRequest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/row/ExternalRequest.ts b/packages/server/src/api/controllers/row/ExternalRequest.ts index 4463dabd5a..852f124ee5 100644 --- a/packages/server/src/api/controllers/row/ExternalRequest.ts +++ b/packages/server/src/api/controllers/row/ExternalRequest.ts @@ -283,7 +283,7 @@ module External { // one to many if (isOneSide(field)) { let id = row[key][0] - if (isNaN(id)) { + if (typeof row[key] === "string") { id = decodeURIComponent(row[key]).match(/\[(.*?)\]/)?.[1] } newRow[field.foreignKey || linkTablePrimary] = breakRowIdField(id)[0] From f4e4311f0833a0faf7def2e9d9c66b0963b5c64e Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 1 Nov 2022 08:11:12 +0000 Subject: [PATCH 4/5] lint --- .../fixtures/types/unpublishAppResponse.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/qa-core/src/config/internal-api/fixtures/types/unpublishAppResponse.ts b/qa-core/src/config/internal-api/fixtures/types/unpublishAppResponse.ts index 83b0c50352..277970fccb 100644 --- a/qa-core/src/config/internal-api/fixtures/types/unpublishAppResponse.ts +++ b/qa-core/src/config/internal-api/fixtures/types/unpublishAppResponse.ts @@ -1,7 +1,7 @@ export interface UnpublishAppResponse { - data: { - ok: boolean - }, - ok: boolean, - status: number + data: { + ok: boolean + } + ok: boolean + status: number } From a57dc85b6068a5ae813d4b2e46b49227117a7e0e Mon Sep 17 00:00:00 2001 From: Mel O'Hagan Date: Tue, 1 Nov 2022 12:37:42 +0000 Subject: [PATCH 5/5] Remove ! from error message --- packages/server/src/api/controllers/row/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/api/controllers/row/index.ts b/packages/server/src/api/controllers/row/index.ts index b921d3df95..09af24a9b1 100644 --- a/packages/server/src/api/controllers/row/index.ts +++ b/packages/server/src/api/controllers/row/index.ts @@ -38,7 +38,7 @@ export async function patch(ctx: any): Promise { } ) if (!row) { - ctx.throw(404, "Row not found!") + ctx.throw(404, "Row not found") } ctx.status = 200 ctx.eventEmitter &&