Skip to content

Commit

Permalink
fix: filtering only root level (VirtusLab-Open-Source#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyp3rius authored Jan 14, 2021
1 parent 753dc0c commit 62a90be
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "strapi-plugin-comments",
"version": "1.0.1-beta.4",
"version": "1.0.1-beta.5",
"description": "Strapi - Comments plugin",
"strapi": {
"name": "Comments",
Expand Down
25 changes: 18 additions & 7 deletions services/comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,36 @@ module.exports = {
// Find comments in the flat structure
async findAllFlat(relation, query) {
const { pluginName, model } = extractMeta(strapi.plugins);
let criteria = {};
let baseCriteria = {};
if (relation) {
criteria = {
...criteria,
baseCriteria = {
...baseCriteria,
relatedSlug: relation,
};
}

let criteria = {
...baseCriteria,
threadOf_null: true,
};
if (query) {
criteria = {
criteria = {
...criteria,
...query,
}
};
}
const entities = query._q ?

const entitiesRoot = query._q ?
await strapi.query( model.modelName, pluginName)
.search(criteria, ['authorUser', 'related', 'reports']) :
await strapi.query( model.modelName, pluginName)
.find(criteria, ['authorUser', 'related', 'reports']);
return entities.map(_ => filterOurResolvedReports(this.sanitizeCommentEntity(_)));
const entitiesNested = await strapi.query( model.modelName, pluginName)
.find({
...baseCriteria,
threadOf_null: false,
}, ['authorUser', 'related', 'reports']);
return [...entitiesRoot, ...entitiesNested].map(_ => filterOurResolvedReports(this.sanitizeCommentEntity(_)));
},

// Find comments and create relations tree structure
Expand Down

0 comments on commit 62a90be

Please sign in to comment.