fix(challenges): handle case where challenge has no categories or result is empty

This commit is contained in:
Matteo Pagliazzi
2020-03-09 21:17:27 +01:00
parent 88bfed7efe
commit 276e882092

View File

@@ -117,20 +117,26 @@ export function createChallengeQuery (query) {
.match(query)
.addFields({
isOfficial: {
$gt: [
{
$size: {
$filter: {
input: '$categories',
as: 'cat',
cond: {
$eq: ['$$cat.slug', 'habitica_official'],
$cond: {
if: { $isArray: '$categories' },
then: {
$gt: [
{
$size: {
$filter: {
input: '$categories',
as: 'cat',
cond: {
$eq: ['$$cat.slug', 'habitica_official'],
},
},
},
},
},
0,
],
},
0,
],
else: false,
},
},
})
.sort('-isOfficial -createdAt');