Add more cases for tags in mongoQueryToFilter

This commit is contained in:
Shweelan Samson authored and Zaid Abdulla committed 2019-03-11 20:07:09 -07:00
1 parent b35ceca8f1
commit 6c6d88e88b
2 files changed
+8 -2

No files matched your search

+3
View File
@@ -458,6 +458,8 @@ export function mongoQueryToFilter(query): Expression {
if (v.hasOwnProperty("$ne")) if (v.hasOwnProperty("$ne"))
expressions.push(["IS NULL", ["PARAM", `Tags.${v["$ne"]}`]]); expressions.push(["IS NULL", ["PARAM", `Tags.${v["$ne"]}`]]);
else if (v.hasOwnProperty("$eq"))
expressions.push(["IS NOT NULL", ["PARAM", `Tags.${v["$eq"]}`]]);
else throw new Error(`Invalid tag query`); else throw new Error(`Invalid tag query`);
} else { } else {
expressions.push(["IS NOT NULL", ["PARAM", `Tags.${v}`]]); expressions.push(["IS NOT NULL", ["PARAM", `Tags.${v}`]]);
@@ -465,6 +467,7 @@ export function mongoQueryToFilter(query): Expression {
} else if (k.startsWith("Tags.")) { } else if (k.startsWith("Tags.")) {
let exists: boolean; let exists: boolean;
if (typeof v === "boolean") exists = v; if (typeof v === "boolean") exists = v;
else if (v.hasOwnProperty("$eq")) exists = !!v["$eq"];
else if (v.hasOwnProperty("$ne")) exists = !v["$ne"]; else if (v.hasOwnProperty("$ne")) exists = !v["$ne"];
else if (v.hasOwnProperty("$exists")) exists = !!v["$exists"]; else if (v.hasOwnProperty("$exists")) exists = !!v["$exists"];
else throw new Error(`Invalid tag query`); else throw new Error(`Invalid tag query`);
+5 -2
View File
@@ -15,8 +15,11 @@ ava("mongoQueryToFilter", t => {
[{ "Tags.test": { $exists: false } }, "Tags.test IS NULL"], [{ "Tags.test": { $exists: false } }, "Tags.test IS NULL"],
[{ "Tags.test": { $ne: true } }, "Tags.test IS NULL"], [{ "Tags.test": { $ne: true } }, "Tags.test IS NULL"],
[{ "Tags.test": { $ne: false } }, "Tags.test IS NOT NULL"], [{ "Tags.test": { $ne: false } }, "Tags.test IS NOT NULL"],
[{ "Tags.test": { $eq: true } }, "Tags.test IS NOT NULL"],
[{ "Tags.test": { $eq: false } }, "Tags.test IS NULL"],
[{ _tags: "test" }, "Tags.test IS NOT NULL"], [{ _tags: "test" }, "Tags.test IS NOT NULL"],
[{ _tags: { $ne: "test" } }, "Tags.test IS NULL"], [{ _tags: { $ne: "test" } }, "Tags.test IS NULL"],
[{ _tags: { $eq: "test" } }, "Tags.test IS NOT NULL"],
[ [
{ $and: [{ test: "test" }, { test: { $ne: "test" } }] }, { $and: [{ test: "test" }, { test: { $ne: "test" } }] },
'test = "test" AND test <> "test"' 'test = "test" AND test <> "test"'
@@ -35,9 +38,9 @@ ava("mongoQueryToFilter", t => {
const shouldFailTests = [ const shouldFailTests = [
[{ test: { $gee: "test" } }, "Operator $gee not supported"], [{ test: { $gee: "test" } }, "Operator $gee not supported"],
[{ test: [] }, "Invalid type"], [{ test: [] }, "Invalid type"],
[{ "Tags.test": { $eq: true } }, "Invalid tag query"], [{ "Tags.test": { $gt: true } }, "Invalid tag query"],
[{ _tags: [] }, "Invalid type"], [{ _tags: [] }, "Invalid type"],
[{ _tags: { $eq: "test" } }, "Invalid tag query"], [{ _tags: { $gt: "test" } }, "Invalid tag query"],
[{ $nor: [] }, "Operator $nor not supported"] [{ $nor: [] }, "Operator $nor not supported"]
]; ];