From 28c8331103b20b19a7b145cb46fcab55b9027eab Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Thu, 20 Aug 2020 16:31:43 +0100 Subject: [PATCH] start of view filters --- .../src/api/controllers/view/viewBuilder.js | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/server/src/api/controllers/view/viewBuilder.js b/packages/server/src/api/controllers/view/viewBuilder.js index 1c8cc49b03..2c2b2f9b62 100644 --- a/packages/server/src/api/controllers/view/viewBuilder.js +++ b/packages/server/src/api/controllers/view/viewBuilder.js @@ -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 }) { return { meta: { field, modelId, groupBy, + filter: [ + { + key: "Status", + condition: "Equals", + value: "VIP", + }, + { + conjunction: "AND" + }, + { + key: "Status", + condition: "Equals", + value: "VIP", + } + ], schema: { sum: "number", min: "number",