Skip to content

Commit

Permalink
feat: begin cron implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementNumericite committed Jun 30, 2021
1 parent dbf637e commit 26bc737
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions back-strapi/config/functions/cron.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,32 @@

module.exports = {
/**
* Simple example.
* Every monday at 1am.
* Send email of daily orders
* Every day at 7am.
*/
// '0 1 * * 1': () => {
//
// }
'* * * * *': async () => {
const environnements = await strapi.services.environnement.find()
const environnement_metropole = environnements.find(_ => _.slug === 'metropole')
const environnement_guyane = environnements.find(_ => _.slug === 'guyane')

let yesterday_7AM = new Date();
yesterday_7AM.setDate(yesterday_7AM.getDate() - 1);
yesterday_7AM.setHours(7);
yesterday_7AM.setMinutes(0);
yesterday_7AM.setMilliseconds(0);

let today_7AM = new Date();
today_7AM.setHours(11);
today_7AM.setMinutes(0);
today_7AM.setMilliseconds(0);

strapi.log.info('', yesterday_7AM)
strapi.log.info('', today_7AM)

const orders = await strapi.services.commande.find({created_at_gte: yesterday_7AM.getTime(), created_at_lt: today_7AM.getTime(), _sort: 'created_date:desc'})

const orders_metropole = 'toto'

strapi.log.debug('', orders[0].box)
}
};

0 comments on commit 26bc737

Please sign in to comment.