start of view filters

This commit is contained in:
Martin McKeaveney 2020-08-20 16:31:43 +01:00
parent 841ee44835
commit 28c8331103
1 changed files with 36 additions and 0 deletions

View File

@ -1,9 +1,45 @@
const TOKEN_MAP = {
EQUALS: "===",
LT: "<",
LTE: "<=",
MT: ">",
MTE: ">=",
CONTAINS: "includes()",
AND: "&&",
OR: "||"
}
function parseFilters(filters) {
const expression = filters.map(filter => {
if (filter.conjunction) return TOKEN_MAP[filter.conjunction];
return `doc["${filter.key}"] ${TOKEN_MAP[filter.condition]} "${filter.value}"`
})
return expression.join(" ")
}
function statsViewTemplate({ field, modelId, groupBy }) { function statsViewTemplate({ field, modelId, groupBy }) {
return { return {
meta: { meta: {
field, field,
modelId, modelId,
groupBy, groupBy,
filter: [
{
key: "Status",
condition: "Equals",
value: "VIP",
},
{
conjunction: "AND"
},
{
key: "Status",
condition: "Equals",
value: "VIP",
}
],
schema: { schema: {
sum: "number", sum: "number",
min: "number", min: "number",