How to refactor the schedule posts for strapi v4

thanks @Daedalus for sharing this solutions with me it’s working

/config/controllers/schedulePost.js

module.exports = {
  schedulePublishArticles: async (strapi) => {
    try {
      const entries = await strapi.entityService.findMany('api::article.article', {
        publicationState: 'preview',
        filters: {
          publishedAt: {$null: true},
          // publish_at: {$lt: new Date()},
        },
      });

      await Promise.all(entries.map(async (article) => {
        return await strapi.entityService.update('api::article.article', article.id, {
          data: {
            publishedAt: new Date()
          }
        })
      }))

    } catch (e) {
      console.log(e.message)
    }
  }
}

config/server/

schedule = require('./controllers/scedulePosts')

module.exports = ({ env }) => ({
  host: env('HOST', '0.0.0.0'),
  port: env.int('PORT', 1337),
  cron :{
    enabled: true,
    tasks: {
      '* * * * *': ({ strapi }) => {
        schedule.schedulePublishArticles(strapi)
      }
    }
  }
});