From 80f3e5954bf5ecb84a8559789fcc50f5b9f5e474 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Fri, 23 Aug 2024 18:30:29 +0100 Subject: [PATCH] Getting processing of SQS relationships working. --- .../src/api/controllers/row/utils/basic.ts | 11 +++++++--- .../src/api/controllers/row/utils/utils.ts | 20 ++++++++++--------- .../src/sdk/app/rows/search/internal/sqs.ts | 13 +++++++++++- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/packages/server/src/api/controllers/row/utils/basic.ts b/packages/server/src/api/controllers/row/utils/basic.ts index f28f650422..8f3607bc73 100644 --- a/packages/server/src/api/controllers/row/utils/basic.ts +++ b/packages/server/src/api/controllers/row/utils/basic.ts @@ -1,5 +1,5 @@ // need to handle table name + field or just field, depending on if relationships used -import { FieldType, Row, Table } from "@budibase/types" +import { FieldSchema, FieldType, Row, Table } from "@budibase/types" import { helpers, PROTECTED_INTERNAL_COLUMNS } from "@budibase/shared-core" import { generateRowIdField } from "../../../../integrations/utils" @@ -82,7 +82,7 @@ export function basicProcessing({ value = value.toString() } // all responses include "select col as table.col" so that overlaps are handled - if (value != null) { + else if (value != null) { thisRow[fieldName] = value } } @@ -93,12 +93,17 @@ export function basicProcessing({ } else { const columns = Object.keys(table.schema) for (let internalColumn of [...PROTECTED_INTERNAL_COLUMNS, ...columns]) { - thisRow[internalColumn] = extractFieldValue({ + const schema: FieldSchema | undefined = table.schema[internalColumn] + let value = extractFieldValue({ row, tableName: table._id!, fieldName: internalColumn, isLinked, }) + if (sqs && schema?.type === FieldType.LINK && typeof value === "string") { + value = JSON.parse(value) + } + thisRow[internalColumn] = value } } return thisRow diff --git a/packages/server/src/api/controllers/row/utils/utils.ts b/packages/server/src/api/controllers/row/utils/utils.ts index 911cfe8d5b..fdf05baf3c 100644 --- a/packages/server/src/api/controllers/row/utils/utils.ts +++ b/packages/server/src/api/controllers/row/utils/utils.ts @@ -147,7 +147,7 @@ export async function sqlOutputProcessing( row._id = rowId } // this is a relationship of some sort - if (finalRows[rowId]) { + if (!opts?.sqs && finalRows[rowId]) { finalRows = await updateRelationshipColumns( table, tables, @@ -174,14 +174,16 @@ export async function sqlOutputProcessing( finalRows[thisRow._id] = fixBooleanFields({ row: thisRow, table }) // do this at end once its been added to the final rows - finalRows = await updateRelationshipColumns( - table, - tables, - row, - finalRows, - relationships, - opts - ) + if (!opts?.sqs) { + finalRows = await updateRelationshipColumns( + table, + tables, + row, + finalRows, + relationships, + opts + ) + } } // make sure all related rows are correct diff --git a/packages/server/src/sdk/app/rows/search/internal/sqs.ts b/packages/server/src/sdk/app/rows/search/internal/sqs.ts index 6736ff6abf..fb140e3c14 100644 --- a/packages/server/src/sdk/app/rows/search/internal/sqs.ts +++ b/packages/server/src/sdk/app/rows/search/internal/sqs.ts @@ -37,9 +37,9 @@ import { outputProcessing } from "../../../../../utilities/rowProcessor" import pick from "lodash/pick" import { processRowCountResponse } from "../../utils" import { - updateFilterKeys, getRelationshipColumns, getTableIDList, + updateFilterKeys, } from "../filters" import { dataFilters, @@ -368,6 +368,17 @@ export async function search( }) ) + // make sure relationships have columns reversed correctly + for (let columnName of Object.keys(table.schema)) { + if (table.schema[columnName].type !== FieldType.LINK) { + continue + } + // process the relationships (JSON generated by SQS) + for (let row of processed) { + row[columnName] = reverseUserColumnMapping(row[columnName]) + } + } + // check for pagination final row let nextRow: boolean = false if (paginate && params.limit && rows.length > params.limit) {