Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
composerjs
composer-service-core
Commits
3d012f71
Commit
3d012f71
authored
Oct 22, 2020
by
Jean-Philippe Steinmetz
Browse files
Fixing query construction to use only or statements with build id query for mongo
parent
0903aa3e
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/models/ModelUtils.ts
View file @
3d012f71
...
...
@@ -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
};
}
/**
...
...
test/ModelUtils.test.ts
View file @
3d012f71
...
...
@@ -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
}]
});
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment