Fix status space query (#2973)

Signed-off-by: Denis Bykhov <bykhov.denis@gmail.com>
This commit is contained in:
Denis Bykhov 2023-04-13 16:00:19 +06:00 committed by GitHub
parent f0928324c5
commit ee085dcc5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -136,8 +136,17 @@ export async function showEmptyGroups (
})
if (query !== undefined) {
const { [key]: st, space } = query
const resQuery: DocumentQuery<Status> = {
space
const resQuery: DocumentQuery<Status> = {}
if (space !== undefined) {
resQuery.space = space
} else {
const spaceRefs = Array.from(new Set(statusList.map((p) => p.space)))
const spaces = await client.findAll(
core.class.Space,
{ _id: { $in: spaceRefs }, archived: false },
{ projection: { _id: 1 } }
)
resQuery.space = { $in: spaces.map((p) => p._id) }
}
if (st !== undefined) {
resQuery._id = st