Do lifecycle hooks work with components?

I did it the following way, which feels a likte hacky (essentially @DMehaffy 's suggetion with more details).

I.e. to update a value you could do the following:

// src/api/[content-type]/content-types/[content-type]/lifecycles.js
let product = await strapi.query('componentGroup.component').findOne({where: {id: event.params.data.Component.id}});
strapi.query('componentGroup.component').update({
      where: {id: product.id},
      data: {
          field1: foo(course.field1)
      }
})

All database operations can be found here:
https://docs.strapi.io/developer-docs/latest/developer-resources/database-apis-reference/query-engine/single-operations.html#create

2 Likes