From 092e75ed6c99de5e29be7c9d67e3023dcb6185b7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 14 May 2024 17:48:10 +0200 Subject: [PATCH] Treat deprecatedSingleUserColumn as single on inputting --- .../utilities/rowProcessor/bbReferenceProcessor.ts | 12 +++++++----- packages/server/src/utilities/rowProcessor/index.ts | 10 +++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts b/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts index 3786079883..874113f6f1 100644 --- a/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts +++ b/packages/server/src/utilities/rowProcessor/bbReferenceProcessor.ts @@ -14,11 +14,13 @@ export async function processInputBBReference( subtype: BBReferenceFieldSubType.USER ): Promise { if (value && Array.isArray(value)) { - throw new InvalidBBRefError( - JSON.stringify(value), - BBReferenceFieldSubType.USER, - "BB_REFERENCE_SINGLE cannot be an array" - ) + if (value.length > 1) { + throw new InvalidBBRefError( + JSON.stringify(value), + BBReferenceFieldSubType.USER + ) + } + value = value[0] } let id = typeof value === "string" ? value : value?._id diff --git a/packages/server/src/utilities/rowProcessor/index.ts b/packages/server/src/utilities/rowProcessor/index.ts index e7bc725285..a3f3ebc8f6 100644 --- a/packages/server/src/utilities/rowProcessor/index.ts +++ b/packages/server/src/utilities/rowProcessor/index.ts @@ -18,6 +18,7 @@ import { processOutputBBReferences, } from "./bbReferenceProcessor" import { isExternalTableID } from "../../integrations/utils" +import { helpers } from "@budibase/shared-core" export * from "./utils" export * from "./attachments" @@ -162,10 +163,13 @@ export async function inputProcessing( if (attachment?.url) { delete clonedRow[key].url } - } else if (field.type === FieldType.BB_REFERENCE && value) { - clonedRow[key] = await processInputBBReferences(value, field.subtype) - } else if (field.type === FieldType.BB_REFERENCE_SINGLE && value) { + } else if ( + field.type === FieldType.BB_REFERENCE_SINGLE || + helpers.schema.isDeprecatedSingleUserColumn(field) + ) { clonedRow[key] = await processInputBBReference(value, field.subtype) + } else if (field.type === FieldType.BB_REFERENCE) { + clonedRow[key] = await processInputBBReferences(value, field.subtype) } }