Return error if no_filters and own_filter are present

This commit is contained in:
Ivan Malagon 2017-12-13 09:45:35 +01:00
parent 811f2bdae3
commit 02ac25181e

View File

@ -37,11 +37,19 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
throw new Error("Dataview '" + dataviewName + "' does not exists"); throw new Error("Dataview '" + dataviewName + "' does not exists");
} }
var pg = new PSQL(dbParamsFromReqParams(params));
var ownFilter = +params.own_filter; var ownFilter = +params.own_filter;
var noFilters = !!params.no_filters; var noFilters = +params.no_filters;
var query = getDaviewQuery(dataviewDefinition, ownFilter, noFilters); if (Number.isFinite(ownFilter) && Number.isFinite(noFilters)) {
err = new Error();
err.message = 'Both own_filter and no_filters cannot be sent in the same request';
err.type = 'dataview';
err.http_status = 400;
return callback(err);
}
var pg = new PSQL(dbParamsFromReqParams(params));
var query = getDataviewQuery(dataviewDefinition, ownFilter, noFilters);
if (params.bbox) { if (params.bbox) {
var bboxFilter = new BBoxFilter({column: 'the_geom_webmercator', srid: 3857}, {bbox: params.bbox}); var bboxFilter = new BBoxFilter({column: 'the_geom_webmercator', srid: 3857}, {bbox: params.bbox});
query = bboxFilter.sql(query); query = bboxFilter.sql(query);
@ -62,7 +70,7 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
); );
}; };
function getDaviewQuery(dataviewDefinition, ownFilter, noFilters) { function getDataviewQuery(dataviewDefinition, ownFilter, noFilters) {
if (noFilters) { if (noFilters) {
return dataviewDefinition.sql.no_filters; return dataviewDefinition.sql.no_filters;
} else if (ownFilter === 1) { } else if (ownFilter === 1) {