Skip to content

Commit

Permalink
fix(knowledgebase): fix count query (#4843)
Browse files Browse the repository at this point in the history
  • Loading branch information
enkhtuvshinD committed Dec 13, 2023
1 parent 154099a commit f887d1a
Showing 1 changed file with 12 additions and 14 deletions.
Expand Up @@ -6,29 +6,27 @@ export const KnowledgeBaseCategory = {
articles(category: ICategoryDocument, _args, { models }: IContext) {
return models.KnowledgeBaseArticles.find({
categoryId: category._id,
status: PUBLISH_STATUSES.PUBLISH,
status: { $in: [PUBLISH_STATUSES.PUBLISH, PUBLISH_STATUSES.DRAFT] }
}).sort({
createdDate: -1,
createdDate: -1
});
},

async authors(category: ICategoryDocument, _args, { models }: IContext) {
const articles = await models.KnowledgeBaseArticles.find(
{
categoryId: category._id,
status: PUBLISH_STATUSES.PUBLISH,
status: { $in: [PUBLISH_STATUSES.PUBLISH, PUBLISH_STATUSES.DRAFT] }
},
{ createdBy: 1 }
);

const authorIds = articles.map((article) => article.createdBy);
const authorIds = articles.map(article => article.createdBy);

return (authorIds || []).map(_id => (
{
__typename: 'User',
_id
}
))
return (authorIds || []).map(_id => ({
__typename: 'User',
_id
}));
},

firstTopic(category: ICategoryDocument, _args, { models }: IContext) {
Expand All @@ -38,17 +36,17 @@ export const KnowledgeBaseCategory = {
numOfArticles(category: ICategoryDocument, _args, { models }: IContext) {
return models.KnowledgeBaseArticles.find({
categoryId: category._id,
status: PUBLISH_STATUSES.PUBLISH,
status: { $in: [PUBLISH_STATUSES.PUBLISH, PUBLISH_STATUSES.DRAFT] }
}).countDocuments();
},
}
};

export const KnowledgeBaseParentCategory = {
...KnowledgeBaseCategory,

childrens(category: ICategoryDocument, _args, { models }: IContext) {
return models.KnowledgeBaseCategories.find({
parentCategoryId: category._id,
parentCategoryId: category._id
}).sort({ title: 1 });
},
}
};

0 comments on commit f887d1a

Please sign in to comment.