Closed NooBiToo closed 3 years ago
@NooBiToo that seem as a case of author field population. By default we're populating just the user
as other nested fields are custom and depends on you own implementation. We're considering a possibility to define the populate
array in the configuration or cover the profile
field by default.
solved
@NooBiToo I'm having the same challenge. Could you share your solution? 🙂
solved
How did you solve it?
@cyp3rius I'm also to start working on this. Could you advise what would be the best way to extend the get comments endpoint? 🤔
@Nisthar I've responded in #80
Please open the new issue / discussion related with Strapi v4 version for clarify and visibility. Do not follow closed issues, rather use them as reference.
@Tragio @Nisthar Hello, I can't remember the exact solution, but I can attach my file to you
'use strict';
const { first, isEmpty, isNil } = require('lodash');
const { sanitizeEntity } = require('strapi-utils');
const PluginError = require('./utils/error');
const { isEqualEntity, extractMeta, buildNestedStructure, checkBadWords, filterOurResolvedReports, convertContentTypeNameToSlug, isValidUserContext, resolveUserContextError } = require('./utils/functions');
/**
* comments.js service
*
* @description: A set of functions similar to controller's actions to avoid code duplication.
*/
module.exports = {
// Find comments in the flat structure
async findAllFlat(relation, query) {
const { pluginName, model } = extractMeta(strapi.plugins);
let baseCriteria = {};
if (relation) {
baseCriteria = {
...baseCriteria,
relatedSlug: relation,
};
}
let criteria = {
...baseCriteria,
threadOf_null: true,
};
if (query) {
criteria = {
...criteria,
...query,
};
}
const entitiesRoot = query && query._q ?
await strapi.query( model.modelName, pluginName)
.search(criteria, ['authorUser', 'authorUser.avatar', 'related', 'reports']) :
await strapi.query( model.modelName, pluginName)
.find(criteria, ['authorUser', 'authorUser.avatar', 'related', 'reports']);
const entitiesNested = await strapi.query( model.modelName, pluginName)
.find({
...baseCriteria,
threadOf_null: false,
}, ['authorUser', 'authorUser.avatar', 'related', 'reports']);
return [...entitiesRoot, ...entitiesNested].map(_ => filterOurResolvedReports(this.sanitizeCommentEntity(_)));
},
// Find comments and create relations tree structure
async findAllInHierarchy (relation, query, startingFromId = null, dropBlockedThreads = false) {
const entities = await this.findAllFlat(relation, query);
return buildNestedStructure(entities, startingFromId, 'threadOf', dropBlockedThreads);
},
sanitizeCommentEntity: (entity) => ({
...entity,
authorUser: sanitizeEntity(entity.authorUser, { model: strapi.plugins['users-permissions'].models.user }),
}),
};
@NooBiToo where do you place this file?
functions.js
@NooBiToo in src/extensions/comments/
?
@NooBiToo in
src/extensions/comments/
?
src/extensions/comments/services/utils/functions.js
@NooBiToo in
src/extensions/comments/
?
src/extensions/comments/services/utils/functions.js
I can't seems to find that function in the original file. are you using v3 of the plugin by any chance?
@NooBiToo in
src/extensions/comments/
?
src/extensions/comments/services/utils/functions.js
I can't seems to find that function in the original file. are you using v3 of the plugin by any chance?
yep this v3)
First, thank you so much for your work.
My user object have avatar object
But there is no such field in the comments