I guess (based on [v4] Filters in `findOne` controller doesn't work · Issue #12208 · strapi/strapi · GitHub) the findOne just does not support filtering.
My current solution was to do this:
async findOne(ctx) {
const { user } = ctx.state;
const { id } = ctx.params;
if (user && typeof user !== 'undefined') {
const entity = await strapi.db.query(contentType).findMany({
where: {
id,
owner: user.id
}
});
const sanitizedEntity = await this.sanitizeOutput(entity, ctx);
return this.transformResponse(sanitizedEntity);
} else {
const sanitizedResults = await this.sanitizeOutput({}, ctx);
return this.transformResponse(sanitizedResults, {});
}
},
But that is not ideal either. I would rather return 404 response in the else part, but I’m not sure how to do that exactly.