feat(core): Auto-wrap get data table row LIKE filter values with wildcards (no-changelog) (#18853)

This commit is contained in:
Daria
2025-08-27 14:31:08 +03:00
committed by GitHub
parent c7c568e682
commit 40c94e2336
2 changed files with 44 additions and 2 deletions

View File

@@ -1796,6 +1796,44 @@ describe('GET /projects/:projectId/data-stores/:dataStoreId/rows', () => {
], ],
}); });
}); });
test.each(['like', 'ilike'])(
'should auto-wrap %s filters if no wildcard is present',
async (condition) => {
const dataStore = await createDataStore(memberProject, {
columns: [
{
name: 'name',
type: 'string',
},
],
data: [
{
name: 'Alice Smith',
},
{
name: 'Bob Jones',
},
{
name: 'Carol Brown',
},
],
});
const filterParam = encodeURIComponent(
JSON.stringify({
type: 'and',
filters: [{ columnName: 'name', value: 'Alice', condition }],
}),
);
const response = await authMemberAgent
.get(`/projects/${memberProject.id}/data-stores/${dataStore.id}/rows?filter=${filterParam}`)
.expect(200);
expect(response.body.data.count).toBe(1);
expect(response.body.data.data[0].name).toBe('Alice Smith');
},
);
}); });
describe('POST /projects/:projectId/data-stores/:dataStoreId/insert', () => { describe('POST /projects/:projectId/data-stores/:dataStoreId/insert', () => {

View File

@@ -107,7 +107,7 @@ export class DataStoreService {
dto: ListDataStoreContentQueryDto, dto: ListDataStoreContentQueryDto,
) { ) {
await this.validateDataStoreExists(dataStoreId, projectId); await this.validateDataStoreExists(dataStoreId, projectId);
this.validateFilters(dto); this.validateAndTransformFilters(dto);
// unclear if we should validate here, only use case would be to reduce the chance of // unclear if we should validate here, only use case would be to reduce the chance of
// a renamed/removed column appearing here (or added column missing) if the store was // a renamed/removed column appearing here (or added column missing) if the store was
@@ -335,7 +335,7 @@ export class DataStoreService {
} }
} }
private validateFilters(dto: ListDataStoreContentQueryDto): void { private validateAndTransformFilters(dto: ListDataStoreContentQueryDto): void {
if (!dto.filter?.filters) { if (!dto.filter?.filters) {
return; return;
} }
@@ -352,6 +352,10 @@ export class DataStoreService {
`${filter.condition.toUpperCase()} filter value must be a string`, `${filter.condition.toUpperCase()} filter value must be a string`,
); );
} }
if (!filter.value.includes('%')) {
filter.value = `%${filter.value}%`;
}
} }
} }
} }