[Bug]: Extending core controllers: Collection type example not working
Link to the documentation page or resource
https://docs.strapi.io/developer-docs/latest/development/backend-customization/controllers.html#extending-core-controllers
Describe the bug
Hello, I tried to extend a core controller as described in the docs:
async find(ctx) {
// some logic here
const { data, meta } = await super.find(ctx);
// some more logic
return { data, meta };
}
even if I only copy & paste, without changing anything I get the following error: TypeError: (intermediate value).find is not a function
Is this a bug in the docs, or am I missing something?
Additional context
I made the changes to the generic controller that was build, when I created a content-type. This is the full code:
'use strict';
/**
* Read the documentation (https://strapi.io/documentation/developer-docs/latest/development/backend-customization.html#core-controllers)
* to customize this controller
*/
module.exports = {
async find(ctx) {
// some logic here
const { data, meta } = await super.find(ctx);
// some more logic
return { data, meta };
}
};
Suggested improvements or fixes
No response
Related issue(s)/PR(s)
No response
Hello @El-Devoper. I am sorry that you didn't receive a response sooner. Hopefully, you were able to solve this problem! If I understand your issue correctly I think the logic is incomplete and should look like this:
'use strict';
/**
* example controller
*/
const { createCoreController } = require('@strapi/strapi').factories;
module.exports = createCoreController('api::example.example', ({ strapi }) => ({
async find(ctx) {
// some logic here
const { data, meta } = await super.find(ctx);
// some more logic
return { data, meta };
}
}));
Let me know if this or something else solved your problem. I am going to start working to make this a little more clear in the documentation.
Indeed we should not have placed them all in one example, we should probably split them
Hello. I'm sorry that you were having troubles and that this issue didn't get more attention sooner. I'm cleaning up old documentation issues. You'd be happy to know this has been re-prioritized and we are actively working on this with engineers from the Strapi core team. You can find more details about our Backend Customization Improvements initiative on Discord.