Lifecycle hook with data on beforePublish

@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