Add more cases for tags in mongoQueryToFilter
This commit is contained in:
1 parent
b35ceca8f1
commit
6c6d88e88b
2 files changed
+8
-2
No files matched your search
@@ -458,6 +458,8 @@ export function mongoQueryToFilter(query): Expression {
|
||||
|
||||
if (v.hasOwnProperty("$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 {
|
||||
expressions.push(["IS NOT NULL", ["PARAM", `Tags.${v}`]]);
|
||||
@@ -465,6 +467,7 @@ export function mongoQueryToFilter(query): Expression {
|
||||
} else if (k.startsWith("Tags.")) {
|
||||
let exists: boolean;
|
||||
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("$exists")) exists = !!v["$exists"];
|
||||
else throw new Error(`Invalid tag query`);
|
||||
|
||||
@@ -15,8 +15,11 @@ ava("mongoQueryToFilter", t => {
|
||||
[{ "Tags.test": { $exists: false } }, "Tags.test IS NULL"],
|
||||
[{ "Tags.test": { $ne: true } }, "Tags.test IS 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: { $ne: "test" } }, "Tags.test IS NULL"],
|
||||
[{ _tags: { $eq: "test" } }, "Tags.test IS NOT NULL"],
|
||||
[
|
||||
{ $and: [{ test: "test" }, { test: { $ne: "test" } }] },
|
||||
'test = "test" AND test <> "test"'
|
||||
@@ -35,9 +38,9 @@ ava("mongoQueryToFilter", t => {
|
||||
const shouldFailTests = [
|
||||
[{ test: { $gee: "test" } }, "Operator $gee not supported"],
|
||||
[{ test: [] }, "Invalid type"],
|
||||
[{ "Tags.test": { $eq: true } }, "Invalid tag query"],
|
||||
[{ "Tags.test": { $gt: true } }, "Invalid tag query"],
|
||||
[{ _tags: [] }, "Invalid type"],
|
||||
[{ _tags: { $eq: "test" } }, "Invalid tag query"],
|
||||
[{ _tags: { $gt: "test" } }, "Invalid tag query"],
|
||||
[{ $nor: [] }, "Operator $nor not supported"]
|
||||
];
|
||||
|
||||
|
||||
Reference in new issue
Block a user