@sap/xsodata
Version:
Expose data from a HANA database as OData V2 service with help of .xsodata files.
36 lines (26 loc) • 922 B
JavaScript
;
const Http400_BadRequest = require('../../utils/errors/http/badRequest');
module.exports = function checkFilterOnAggregatedColumn(context, callback) {
const aggs = context.oData.dbSegmentLast.entityType.getAggregates();
const filter = context.oData.systemQueryParameters.filter;
if (aggs.length === 0 || !filter) {
return callback(null, context);
}
if (check(aggs, filter)) {
return callback(createError(), context);
}
return callback(null, context);
};
function createError() {
const errorMessage = '$filter is not allowed for aggregated columns.';
return new Http400_BadRequest(errorMessage);
}
function check(aggs, type) {
let violation = aggs.some(function (agg) {
return agg.column === type.property;
});
if (!violation) {
violation = type.getChildren().some(check.bind(null, aggs));
}
return violation;
}