Stripping out conjunction in view filter if its the first one.

This commit is contained in:
mike12345567 2021-04-28 14:57:52 +01:00
parent cb803b1abf
commit 102f4bf1d4
1 changed files with 9 additions and 1 deletions

View File

@ -62,8 +62,11 @@ const SCHEMA_MAP = {
function parseFilterExpression(filters) {
const expression = []
let first = true
for (let filter of filters) {
if (filter.conjunction) expression.push(TOKEN_MAP[filter.conjunction])
if (!first && filter.conjunction) {
expression.push(TOKEN_MAP[filter.conjunction])
}
if (filter.condition === "CONTAINS") {
expression.push(
@ -77,6 +80,7 @@ function parseFilterExpression(filters) {
`doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} ${value}`
)
}
first = false
}
return expression.join(" ")
@ -104,6 +108,10 @@ function parseEmitExpression(field, groupBy) {
* calculation: an optional calculation to be performed over the view data.
*/
function viewTemplate({ field, tableId, groupBy, filters = [], calculation }) {
// first filter can't have a conjuction
if (filters && filters.length > 0 && filters[0].conjunction) {
delete filters[0].conjunction
}
const parsedFilters = parseFilterExpression(filters)
const filterExpression = parsedFilters ? `&& ${parsedFilters}` : ""