I'm new with plugins, I want build a plugin simple to automatic update quantity inventory of product

help me code please.

This topic has been created from a Discord post (1231205767281905695) to give it more visibility.
It will be on Read-Only mode here.
Join the conversation on Discord

I want when the records inside the Order Collection change the order status from pending to approval, the quantity of goods in the Inventory Collection will automatically be deducted. I’ve got collections built using the UI admin panel.

You normally do that via bootstrap function by placing a db lifecycle subscriber

thanks ser

I saw a guys this code;

register({ strapi }) {
const entity = “api::page.page”;
const { lifecycles } = strapi.contentType(entity);
strapi.contentType(entity).lifecycles = {
…lifecycles,
async beforeUpdate() {
console.log(“hello from plugin”);
},
};
},

So this is still working but hard, right?
:rofl:

The bootstrap is a better place

And normally you do that via:
strapi.db.lifecycles.subscribe

So can I write this business logic into a separate plugin? no need to write inside the api anymore?