mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
feat(core): Auto-wrap get data table row LIKE filter values with wildcards (no-changelog) (#18853)
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -107,7 +107,7 @@ export class DataStoreService {
|
||||
dto: ListDataStoreContentQueryDto,
|
||||
) {
|
||||
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
|
||||
// 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) {
|
||||
return;
|
||||
}
|
||||
@@ -352,6 +352,10 @@ export class DataStoreService {
|
||||
`${filter.condition.toUpperCase()} filter value must be a string`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!filter.value.includes('%')) {
|
||||
filter.value = `%${filter.value}%`;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user