Commit 3d012f71 authored by Jean-Philippe Steinmetz's avatar Jean-Philippe Steinmetz
Browse files

Fixing query construction to use only or statements with build id query for mongo

parent 0903aa3e
......@@ -115,14 +115,14 @@ class ModelUtils {
// e.g. WHERE idField1 = :idField1 OR idField2 = :idField2 ...
const query: any[] = [];
for (const prop of props) {
query.push({ [prop]: id });
if (version !== undefined) {
query.push({ [prop]: id, version });
} else {
query.push({ [prop]: id });
}
}
if (version !== undefined) {
return { $and: [{ $or: query }, { version }] };
} else {
return { $or: query };
}
return { $or: query };
}
/**
......
......@@ -52,24 +52,14 @@ describe("ModelUtils Tests", () => {
it("Can build id search query with single identifier and version.", () => {
const query: any = ModelUtils.buildIdSearchQueryMongo(SingleIdentifierClass, "MyID", 2);
expect(query).toEqual({
$and: [{
$or: [{ id: "MyID" }]
},
{
version: 2
}]
$or: [{ id: "MyID", version: 2 }]
});
});
it("Can build id search query with single identifier and version 0.", () => {
const query: any = ModelUtils.buildIdSearchQueryMongo(SingleIdentifierClass, "MyID", 0);
expect(query).toEqual({
$and: [{
$or: [{ id: "MyID" }]
},
{
version: 0
}]
$or: [{ id: "MyID", version: 0 }]
});
});
......@@ -83,10 +73,7 @@ describe("ModelUtils Tests", () => {
it("Can build id search query with multiple identifiers and version.", () => {
const query: any = ModelUtils.buildIdSearchQueryMongo(DoubleIdentifierClass, "MyID", 3);
expect(query).toEqual({
$and: [
{ $or: [{ id: "MyID" }, { id2: "MyID" }] },
{ version: 3 }
]
$or: [{ id: "MyID", version: 3 }, { id2: "MyID", version: 3 }]
});
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment