Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
filteredColumns.forEach(filterableColumn => {
request.columns.find(column => column.name == filterableColumn.name).hasFilter = true;
switch (filterableColumn.filter.operator) {
case CompareOperators.Equals:
subset = subset.filter(row => row[filterableColumn.name] == filterableColumn.filter.text);
break;
case CompareOperators.NotEquals:
subset = subset.filter(row => row[filterableColumn.name] != filterableColumn.filter.text);
break;
case CompareOperators.Contains:
subset = subset.filter(row => row[filterableColumn.name].indexOf(filterableColumn.filter.text) >= 0);
break;
case CompareOperators.NotContains:
subset = subset.filter(row => row[filterableColumn.name].indexOf(filterableColumn.filter.text) < 0);
break;
case CompareOperators.StartsWith:
subset = subset.filter(row => row[filterableColumn.name].toLowerCase().startsWith(filterableColumn.filter.text));
break;
case CompareOperators.NotStartsWith:
subset = subset.filter(row => !row[filterableColumn.name].toLowerCase().startsWith(filterableColumn.filter.text));
break;
case CompareOperators.EndsWith:
subset = subset.filter(row => row[filterableColumn.name].toLowerCase().endsWith(filterableColumn.filter.text));
break;
case CompareOperators.NotEndsWith:
subset = subset.filter(row => !row[filterableColumn.name].toLowerCase().endsWith(filterableColumn.filter.text));
break;
// TODO: check for types
case CompareOperators.Gt:
it("filters using NotContains", done => {
const take = 10,
filteredCount = 594;
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'ley',
argument: [],
operator: CompareOperators.NotContains,
hasFilter: false
}
},
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0,
'',
);
let queryBuilder = knex.select('first_name', 'last_name', 'address_id').from('customer');
tubular.createGridResponse(request, queryBuilder)
.then(response => {
expect(response.counter).toBeDefined();
it("filters using NotContains", done => {
const take = 10,
filteredCount = 48;
let request = new GridRequest(
[
{
name: 'first_name', label: 'First Name', sortable: true, searchable: true, filter: {
name: '',
text: 'ley',
argument: [],
operator: CompareOperators.NotContains,
hasFilter: false
}
},
{ name: 'last_name', label: 'Last Name', sortable: true, searchable: true },
{ name: 'address_id', label: 'Address Id', sortable: true, searchable: false }
],
take,
0
);
tubular.createGridResponse(request, data)
.then(response => {
expect(response.counter).toBeDefined();
expect(response.totalRecordCount).toBe(totalRecordCount);
expect(response.filteredRecordCount).toBe(filteredCount);
expect(response.totalPages).toBe(Math.ceil(filteredCount / take));
filteredColumns.forEach(filterableColumn => {
request.columns.find(column => column.name == filterableColumn.name).HasFilter = true;
switch (filterableColumn.filter.operator) {
case CompareOperators.Equals:
subset = subset.where(filterableColumn.name, filterableColumn.filter.text);
break;
case CompareOperators.NotEquals:
subset = subset.whereNot(filterableColumn.name, filterableColumn.filter.text);
break;
case CompareOperators.Contains:
subset = subset.where(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}%`);
break;
case CompareOperators.NotContains:
subset = subset.whereNot(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}%`);
break;
case CompareOperators.StartsWith:
subset = subset.where(filterableColumn.name, 'LIKE', `${filterableColumn.filter.text}%`);
break;
case CompareOperators.NotStartsWith:
subset = subset.whereNot(filterableColumn.name, 'LIKE', `${filterableColumn.filter.text}%`);
break;
case CompareOperators.EndsWith:
subset = subset.where(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}`);
break;
case CompareOperators.NotEndsWith:
subset = subset.whereNot(filterableColumn.name, 'LIKE', `%${filterableColumn.filter.text}`);
break;
case CompareOperators.Gt:
case CompareOperators.Gte: