Get userinfo from createdBy and updatedBy v4

After reading this topic https://forum.strapi.io/t/cant-get-createdby-from-api/15687/2
I was able to add the information to the content-type.

If someone have a better way of doing this feel free to comment.

    async findOne(ctx){
        const { id } = ctx.params;
        const data = await strapi.db.query('api::wiki.wiki').findOne({
            where: {
                url_slug_full: id.replaceAll('%252F','/').replaceAll('%2F','/'),
            },
            populate: ['createdBy', 'updatedBy'],
        });
        const sanitizedEntity = await this.sanitizeOutput(data, ctx);
        sanitizedEntity.createdBy = {
            id: data.createdBy.id,
            email: data.createdBy.email
        };
        sanitizedEntity.updatedBy = {
            id: data.updatedBy.id,
            email: data.updatedBy.email
        };
        return this.transformResponse(sanitizedEntity);
    }
1 Like