Hirad
1
System Information
-
Strapi Version: 4.2
-
Operating System: windows 10
-
Node Version: 16.14.2
-
NPM Version: 8.9.0
I get everything except author, how can I get this dependency? I have already worn out no strength.
Hirad
2
Found a solution to the problem.
The controllers
'use strict';
/**
* comment-blog controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::comment-blog.comment-blog', ({ strapi }) => ({
async find(ctx) {
ctx.query = { ...ctx.query, populate: ['author.avatar'] }
const { data, meta } = await super.find(ctx);
return { data, meta };
}
}));
In services
'use strict';
/**
* comment-blog service.
*/
const { createCoreService } = require('@strapi/strapi').factories;
module.exports = createCoreService('api::comment-blog.comment-blog', ({ strapi }) => ({
async find(...args) {
const { results, pagination } = await super.find(...args);
results.forEach(result => {
const { author: { id, username, confirmed, blocked, avatar: { formats: { thumbnail } } } } = result
result.user = { id, username, confirmed, blocked, thumbnail };
});
return { results, pagination };
},
}));