Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Sortable: true
});
// Column samples
const validColumnsSample = [
regularOrderIdCol,
new ColumnModel('CustomerName', {
Aggregate: AggregateFunctions.COUNT,
Filterable: true,
Searchable: true
}),
new ColumnModel('ShippedDate', {
DataType: ColumnDataType.DATE_TIME,
Filterable: true
}),
new ColumnModel('ShipperCity'),
new ColumnModel('Amount', { DataType: ColumnDataType.NUMERIC })
];
export { validColumnsSample };
import {
AggregateFunctions,
ColumnDataType,
ColumnModel,
ColumnSortDirection
} from 'tubular-common';
const regularOrderIdCol = new ColumnModel('OrderID', {
DataType: ColumnDataType.NUMERIC,
Filterable: true,
IsKey: true,
SortDirection: ColumnSortDirection.ASCENDING,
SortOrder: 1,
Sortable: true
});
// Column samples
const validColumnsSample = [
regularOrderIdCol,
new ColumnModel('CustomerName', {
Aggregate: AggregateFunctions.COUNT,
Filterable: true,
Searchable: true
}),
new ColumnModel('ShippedDate', {
});
// Column samples
const validColumnsSample = [
regularOrderIdCol,
new ColumnModel('CustomerName', {
Aggregate: AggregateFunctions.COUNT,
Filterable: true,
Searchable: true
}),
new ColumnModel('ShippedDate', {
DataType: ColumnDataType.DATE_TIME,
Filterable: true
}),
new ColumnModel('ShipperCity'),
new ColumnModel('Amount', { DataType: ColumnDataType.NUMERIC })
];
export { validColumnsSample };
IsKey: true,
SortDirection: ColumnSortDirection.ASCENDING,
SortOrder: 1,
Sortable: true
});
// Column samples
const validColumnsSample = [
regularOrderIdCol,
new ColumnModel('CustomerName', {
Aggregate: AggregateFunctions.COUNT,
Filterable: true,
Searchable: true
}),
new ColumnModel('ShippedDate', {
DataType: ColumnDataType.DATE_TIME,
Filterable: true
}),
new ColumnModel('ShipperCity'),
new ColumnModel('Amount', { DataType: ColumnDataType.NUMERIC })
];
export { validColumnsSample };
import {
AggregateFunctions,
ColumnDataType,
ColumnModel,
ColumnSortDirection
} from 'tubular-common';
const regularOrderIdCol = new ColumnModel('OrderID', {
DataType: ColumnDataType.NUMERIC,
Filterable: true,
IsKey: true,
SortDirection: ColumnSortDirection.ASCENDING,
SortOrder: 1,
Sortable: true
});
// Column samples
const validColumnsSample = [
regularOrderIdCol,
new ColumnModel('CustomerName', {
Aggregate: AggregateFunctions.COUNT,
Filterable: true,
Searchable: true
}),
new ColumnModel('ShippedDate', {
DataType: ColumnDataType.DATE_TIME,
Filterable: true
}),
switch (column.aggregate) {
case AggregateFunctions.Sum:
value = _.sumBy(subset, column.name);
break;
case AggregateFunctions.Average:
value = _.meanBy(subset, column.name);
break;
case AggregateFunctions.Max:
// .maxBy returns the object containing the max value
value = _.maxBy(subset, column.name)[column.name];
break;
case AggregateFunctions.Min:
// .minBy returns the object containing the min value
value = _.minBy(subset, column.name)[column.name];
break;
case AggregateFunctions.Count:
value = subset.length;
break;
case AggregateFunctions.DistinctCount:
value = _.uniqWith(subset, (a, b) => {
return a[column.name] == b[column.name];
}).length;
break;
default:
throw 'Unsupported aggregate function';
}
return { [column.name]: value };
});
const results = _.map(aggregateColumns, column => {
let value;
switch (column.aggregate) {
case AggregateFunctions.Sum:
value = _.sumBy(subset, column.name);
break;
case AggregateFunctions.Average:
value = _.meanBy(subset, column.name);
break;
case AggregateFunctions.Max:
// .maxBy returns the object containing the max value
value = _.maxBy(subset, column.name)[column.name];
break;
case AggregateFunctions.Min:
// .minBy returns the object containing the min value
value = _.minBy(subset, column.name)[column.name];
break;
case AggregateFunctions.Count:
value = subset.length;
break;
return Promise.all(_.map(aggregateColumns, column => {
// Do not disrupt the original query chain
let copyOfSubset = subset.clone();
// in order to work with aggregates
copyOfSubset.clearSelect();
switch (column.aggregate) {
case AggregateFunctions.Sum:
copyOfSubset = copyOfSubset.sum(`${column.name} as tbResult`);
break;
case AggregateFunctions.Average:
copyOfSubset = copyOfSubset.avg(`${column.name} as tbResult`);
break;
case AggregateFunctions.Max:
copyOfSubset = copyOfSubset.max(`${column.name} as tbResult`);
break;
case AggregateFunctions.Min:
copyOfSubset = copyOfSubset.min(`${column.name} as tbResult`);
break;
case AggregateFunctions.Count:
copyOfSubset = copyOfSubset.count(`${column.name} as tbResult`);
break;
case AggregateFunctions.DistinctCount:
copyOfSubset = copyOfSubset.countDistinct(`${column.name} as tbResult`);
subset = subset.filter(row => !row[filterableColumn.name].toLowerCase().endsWith(filterableColumn.filter.text));
break;
// TODO: check for types
case CompareOperators.Gt:
subset = subset.filter(row => row[filterableColumn.name] > filterableColumn.filter.text);
break;
case CompareOperators.Gte:
subset = subset.filter(row => row[filterableColumn.name] >= filterableColumn.filter.text);
break;
case CompareOperators.Lt:
subset = subset.filter(row => row[filterableColumn.name] < filterableColumn.filter.text);
break;
case CompareOperators.Lte:
subset = subset.filter(row => row[filterableColumn.name] <= filterableColumn.filter.text);
break;
case CompareOperators.Between:
subset = subset.filter(row => row[filterableColumn.name] > filterableColumn.filter.text && row[filterableColumn.name] < filterableColumn.filter.argument[0]);
break;
default:
throw 'Unsupported Compare Operator';
}
});
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:
subset = subset.filter(row => row[filterableColumn.name] > filterableColumn.filter.text);
break;
case CompareOperators.Gte:
subset = subset.filter(row => row[filterableColumn.name] >= filterableColumn.filter.text);
break;
case CompareOperators.Lt:
subset = subset.filter(row => row[filterableColumn.name] < filterableColumn.filter.text);
break;
case CompareOperators.Lte: