My client would like to be able to administrate her orders, whether creating or updating them from Strapi’s dashboard. It seems like I can’t call controller in ‘api/orders/controller/order.js’ from admin’s dashboard, I can only from API.
I saw that model is called everytime in ‘api/orders/models/order.js’.
Where am I supposed to write my code for Stripe’s call (for example) etc ?
Should I do everything in the model’s ‘beforeCreate’ then ?
And why is model working everywhere and not controller ??
I’m building an e-commerce website for a client.
She would like to be able to create or update orders she receives, and I would like to create orders from the website.
But there are conditions about these orders, like the connection to Stripe for example, the calculous of the amount (which I put in the model already)…
So that’s it, I want to call a controller from my API (it’s already the case, it gets called) AND from Strapi’s admin dashboard (my client, and it’s easier to test for me also, but controller isn’t called)
// api/order/controllers/order.js
// This gets called from my API, but not from admin's dashboard, while model gets called for both
module.exports = {
create: async ctx => {
console.log('Creating...');
const order = await strapi.services.order.create(ctx.request.body);
return sanitizeEntity(order, { model: strapi.models.order });
},
};
You can use lifecycles for this to trigger your create service from Strapi’s admin.
module.exports = {
lifecycles: {
// Called before an entry is created
beforeCreate(data) {
//trigger your custom code here
},
// Called after an entry is created
afterCreate(result) {
},
},
};
I have the same problem as in controller, this code isn’t called in service in ‘api/order/services/order.js’, when I create an order from Strapi’s admin dashboard: