Lifecycle hook with data on beforePublish

Hey, I can’t see the beforePublish lifecycle hook, but I would really like to validate the entity fields on the backend side before publishing, is it possible to do so?

And also, I’ve got an array of components that is required, but I can save and publish without creating an any instance of those :frowning:

@Dzmitry_Baranau use beforeUpdate lifecycle method with condition “published_at != null” like that:

async beforeUpdate(params, data) {
  const news = await strapi.query("news-item").findOne({ id: params.id });
  const newsUpdated = { ...news, ...data };

  if (newsUpdated.published_at != null) {
    if (newsUpdated.user == null) {
      const err = new Error("Please set up User field");
      const boomError = Boom.boomify(err, {
        statusCode: 422,
      });
      throw boomError;
    }
  }
}
4 Likes

@AntonioDeCasper as we want to do it not on update but on publish of that item ?