Hi, when I override a v4 service/controller it works as expected when called with REST/GraphQL api but doesn’t call when I modify the data from Admin Panel.
@xantiagoma So finally I found the way to do it for me. I am not sure the best aproach,but you can do something inside of test/content-types/test/, create a lifecycles.js doc and create a this funcions
module.exports = {
async afterUpdate(event) {
// some logic here
if (
//compare you new data with old to avoid infinite loop
) {
await strapi.db.query('api::test.test').update({
where: { id: event.params.where.id },
data: {
...data,
// some logic here
},
});
}
},
}
Hmm this is not ideal. Controller update should work. Create gets called from admin panel queries but not update which is strange. Update gets called when using the rest api. So it doesnt make sense.
I dont like using the lifecycle for this because in my case the logic should be in the controller.
It seems when extending the controllers the update method does not get called so you cannot extend the update method for any controllers. Seems like a flaw.
The update method does not get called at all. I have my debugger setup and I added console logs. Update method only gets hit when updating via rest api and does not get hit when updating via admin panel.