Merge pull request #12002 from Budibase/fix/users-column-search-mapping

Fix/users column search mapping
This commit is contained in:
Adria Navarro 2023-10-09 13:54:54 +02:00 committed by GitHub
commit afedd560fd
2 changed files with 73 additions and 50 deletions

View File

@ -20,7 +20,21 @@ const tableWithUserCol: Table = {
}, },
} }
describe("searchInputMapping", () => { const tableWithUsersCol: Table = {
_id: tableId,
name: "table",
schema: {
user: {
name: "user",
type: FieldType.BB_REFERENCE,
subtype: FieldTypeSubtypes.BB_REFERENCE.USERS,
},
},
}
describe.each([tableWithUserCol, tableWithUsersCol])(
"searchInputMapping",
col => {
const globalUserId = dbCore.generateGlobalUserID() const globalUserId = dbCore.generateGlobalUserID()
const userMedataId = dbCore.generateUserMetadataID(globalUserId) const userMedataId = dbCore.generateUserMetadataID(globalUserId)
@ -33,7 +47,7 @@ describe("searchInputMapping", () => {
}, },
}, },
} }
const output = searchInputMapping(tableWithUserCol, params) const output = searchInputMapping(col, params)
expect(output.query.equal!["1:user"]).toBe(globalUserId) expect(output.query.equal!["1:user"]).toBe(globalUserId)
}) })
@ -46,7 +60,7 @@ describe("searchInputMapping", () => {
}, },
}, },
} }
const output = searchInputMapping(tableWithUserCol, params) const output = searchInputMapping(col, params)
expect(output.query.oneOf!["1:user"]).toStrictEqual([ expect(output.query.oneOf!["1:user"]).toStrictEqual([
globalUserId, globalUserId,
globalUserId, globalUserId,
@ -63,7 +77,7 @@ describe("searchInputMapping", () => {
}, },
}, },
} }
const output = searchInputMapping(tableWithUserCol, params) const output = searchInputMapping(col, params)
expect(output.query.equal!["1:user"]).toBe(email) expect(output.query.equal!["1:user"]).toBe(email)
}) })
@ -71,7 +85,8 @@ describe("searchInputMapping", () => {
const params: any = { const params: any = {
tableId, tableId,
} }
const output = searchInputMapping(tableWithUserCol, params) const output = searchInputMapping(col, params)
expect(output.query).toBeUndefined() expect(output.query).toBeUndefined()
}) })
}) }
)

View File

@ -5,8 +5,10 @@ import {
Table, Table,
DocumentType, DocumentType,
SEPARATOR, SEPARATOR,
FieldSubtype,
} from "@budibase/types" } from "@budibase/types"
import { db as dbCore } from "@budibase/backend-core" import { db as dbCore } from "@budibase/backend-core"
import { utils } from "@budibase/shared-core"
function findColumnInQueries( function findColumnInQueries(
column: string, column: string,
@ -66,8 +68,14 @@ export function searchInputMapping(table: Table, options: SearchParams) {
for (let [key, column] of Object.entries(table.schema)) { for (let [key, column] of Object.entries(table.schema)) {
switch (column.type) { switch (column.type) {
case FieldType.BB_REFERENCE: case FieldType.BB_REFERENCE:
if (column.subtype === FieldTypeSubtypes.BB_REFERENCE.USER) { const subtype = column.subtype as FieldSubtype
switch (subtype) {
case FieldSubtype.USER:
case FieldSubtype.USERS:
userColumnMapping(key, options) userColumnMapping(key, options)
break
default:
utils.unreachable(subtype)
} }
break break
} }