Customs function after creating element on admin panel

Hello there,

I want to add a tag ‘last article’ on a new article when a contributor is creating one on the admin panel (removing the tag from the latest one and tag the newest).

Is there a way to create a function like this on the controller ? When I try to redefine the create function it does not work

thanks for you help

Hi @Antoine6,

in general you’re right: A controller would be a good fit for this. Do you have some code example of your current implementation? Updating the built-in implementation that can be found in the documentation should just work fine so that’s why some code snippet would be great to check what is going wrong there :slight_smile:

Cheers

Hello ! thanks for you replay,

here is my implementation :

Routes

{
  "routes": [
    {
      "method": "GET",
      "path": "/articles",
      "handler": "article.find",
      "config": {
        "policies": []
      }
    },
    {
      "method": "GET",
      "path": "/articles/count",
      "handler": "article.count",
      "config": {
        "policies": []
      }
    },
    {
      "method": "GET",
      "path": "/articles/:id",
      "handler": "article.findOne",
      "config": {
        "policies": []
      }
    },
    {
      "method": "POST",
      "path": "/articles",
      "handler": "article.create",
      "config": {
        "policies": []
      }
    },
    {
      "method": "PUT",
      "path": "/articles/:id",
      "handler": "article.update",
      "config": {
        "policies": []
      }
    },
    {
      "method": "DELETE",
      "path": "/articles/:id",
      "handler": "article.delete",
      "config": {
        "policies": []
      }
    }
  ]
}

controllers :

module.exports = {
    create : async ctx => {
        console.log('hi')
    }
};

when I insert a new article on the admin panel with the “Add new articles” button, nothing happen on my terminal and the article is well created.