Fixing issue discovered by test with 1: syntax being required for relationship based filters.

This commit is contained in:
mike12345567 2024-05-21 18:39:46 +01:00
parent 0561ca6e1b
commit a5c5e2ffcd
1 changed files with 7 additions and 9 deletions

View File

@ -55,8 +55,8 @@ function buildInternalFieldList(
return fieldList
}
function tableInFilter(name: string) {
return `:${name}.`
function tableNameInFieldRegex(tableName: string) {
return new RegExp(`^${tableName}.|:${tableName}.`, "g")
}
function cleanupFilters(filters: SearchFilters, tables: Table[]) {
@ -72,15 +72,13 @@ function cleanupFilters(filters: SearchFilters, tables: Table[]) {
// relationship, switch to table ID
const tableRelated = tables.find(
table =>
table.originalName && key.includes(tableInFilter(table.originalName))
table.originalName &&
key.match(tableNameInFieldRegex(table.originalName))
)
if (tableRelated && tableRelated.originalName) {
filter[
key.replace(
tableInFilter(tableRelated.originalName),
tableInFilter(tableRelated._id!)
)
] = filter[key]
// only replace the first, not replaceAll
filter[key.replace(tableRelated.originalName, tableRelated._id!)] =
filter[key]
delete filter[key]
}
}