Custom endpoint to return user data with additional fields via relation

UPDATE: I was able to get it working by doing this:

module.exports = {
    async index(ctx, next) {
        const id = ctx.state?.user?.id

        const account = await strapi
            .query("api::profile.profile")
            .findOne({
                where: { user: id },
                populate: {
                    billing: true,
                    shipping: true,
                    user: true
                }
            })

        ctx.body = account
    },
};

But please note that the syntax for the .findOne() params is VERY different from the one I found in the docs. The documentation is really all over the place :frowning:

Anyway, is what I am doing the correct way to achieve this or does anyone have suggestions on how to improve it?

3 Likes