Hello guys im creating a custom service on the new v4 strapi following the docs this is my code:
const { createCoreService } = require('@strapi/strapi').factories;
// createPlan code ommited for simplicity
module.exports = createCoreService('api::payments.payments', ({ strapi }) => ({
async createPlan(config){
console.log(config)
let localPlan = await createStripePlan(config, false);
let globalPlan = await createStripePlan(config, true);
return {
localPlan,
globalPlan,
}
}
}))
Im trying to use this service on a lifecycle as follow:
module.exports = {
async beforeCreate (event) {
let plan = event.params.data
let planConfig = {
name: plan.name,
basePrice: plan.basePrice,
usdPrice: plan.usdPrice,
products: plan.productsQuota,
orders: plan.ordersQuota,
users: plan.usersQuota,
channels: plan.channelsQuota
}
let products = await strapi.service("api::payments.payments").createPlan(planConfig)
if(products){
event.params.data.stripeLocalProductId = products.localPlan.id
event.params.data.stripeGlobalProductId = products.globalPlan.id
}
},
async beforeUpdate (event) {
let plan = event.params.data
let planConfig = {
name: plan.name,
basePrice: plan.basePrice,
usdPrice: plan.usdPrice,
products: plan.productsQuota,
orders: plan.ordersQuota,
users: plan.usersQuota,
channels: plan.channelsQuota
}
let products = await strapi.service("api::payments.payments").createPlan(planConfig)
if(products){
event.params.data.stripeLocalProductId = products.localPlan.id
event.params.data.stripeGlobalProductId = products.globalPlan.id
}
}
}
When I save the object on the admin dashboard triggering the lifecycle method I have seen this error on the console.
error: Cannot read property ‘kind’ of undefined
0|fenicia-strapi | TypeError: Cannot read property ‘kind’ of undefined
0|fenicia-strapi | at isSingleType (/srv/fenicia-strapi/node_modules/@strapi/utils/lib/content-types.js:90:25)
0|fenicia-strapi | at createService (/srv/fenicia-strapi/node_modules/@strapi/strapi/lib/core-api/service/index.js:21:7)
0|fenicia-strapi | at /srv/fenicia-strapi/node_modules/@strapi/strapi/lib/factories.js:30:25
0|fenicia-strapi | at Object.get (/srv/fenicia-strapi/node_modules/@strapi/strapi/lib/core/registries/services.js:36:69)
0|fenicia-strapi | at Strapi.service (/srv/fenicia-strapi/node_modules/@strapi/strapi/lib/Strapi.js:95:43)
0|fenicia-strapi | at Object.beforeUpdate (/srv/fenicia-strapi/src/api/plan/content-types/plan/lifecycles.js:45:38)
0|fenicia-strapi | at modelsLifecyclesSubscriber (/srv/fenicia-strapi/node_modules/@strapi/database/lib/lifecycles/subscribers/models-lifecycles.js:15:41)
0|fenicia-strapi | at Object.run (/srv/fenicia-strapi/node_modules/@strapi/database/lib/lifecycles/index.js:47:17)
0|fenicia-strapi | at processTicksAndRejections (internal/process/task_queues.js:97:5)
0|fenicia-strapi | at async Object.update (/srv/fenicia-strapi/node_modules/@strapi/database/lib/entity-manager.js:217:7)
0|fenicia-strapi | at async Object.update (/srv/fenicia-strapi/node_modules/@strapi/strapi/lib/services/entity-service/index.js:219:18)
0|fenicia-strapi | at async Object. (/srv/fenicia-strapi/node_modules/@strapi/strapi/lib/services/entity-service/index.js:67:20)
0|fenicia-strapi | at async Object.update (/srv/fenicia-strapi/node_modules/@strapi/plugin-i18n/server/services/entity-service-decorator.js:142:19)
0|fenicia-strapi | at async Object.update (/srv/fenicia-strapi/node_modules/@strapi/plugin-content-manager/server/controllers/collection-types.js:123:27)
0|fenicia-strapi | at async returnBodyMiddleware (/srv/fenicia-strapi/node_modules/@strapi/strapi/lib/services/server/compose-endpoint.js:52:18)
0|fenicia-strapi | at async module.exports (/srv/fenicia-strapi/node_modules/@strapi/plugin-content-manager/server/middlewares/routing.js:39:3)
For me it is happening on the service factory but i don’t know what is happening
Did I missed something? Is the service correctly created?
System Information
- Strapi Version: v4
- Operating System: ubuntu
- Database: mysql RDS
- Node Version:
- NPM Version:
- Yarn Version: