Skip to content

Modify/extend endpoints response #155

Open
@javier-creativedog-agency

Description

Hi, first of all, great plugin! It has been very useful.

We are trying to modify/extend the response of one endpoint: /api/menus/:ID, basically we need to add some data to the response object.
and we are using this guide as reference: https://docs.strapi.io/dev-docs/plugins-extension#within-the-extensions-folder.

//File: src/extensions/menus/strapi-server.js

module.exports = (plugin) => {
  const defaultAttrs = plugin.contentTypes["menu-item"].schema.attributes;

  const customAttrs = {
    category: {
      type: "relation",
      relation: "oneToOne",
      target: "api::category.category",
    },
  };

  plugin.contentTypes["menu-item"].schema.attributes = {
    ...defaultAttrs,
    ...customAttrs,
  };

  console.log(plugin.controllers.menu);

  return plugin;
};

We used this strategy in previous developments modifying plugins but this time when trying to get the required controller (plugin.controllers.menu) instead of getting an object with the default methods like in any other plugin (find, findOne, create, etc.), we are getting an anonymous function, presumably because plugin.controllers.menu is set via createCoreController function, so we can't modify the findOne method like in others plugins.

Our question is: There is a preferred way to extend or modify the response specific to this plugin? Is it even possible?

Thanks in advance for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions