I am attempting to filter content pieces that are between 3 and 30 days old and then change their related category. I am doing this via cron jobs so that it can happen every day at midnight. However, even though I have content pieces that fit this category, none are being retrieved and updated. Does the $between filter work with dates? Or only integers? Please see associated code below.
"0 0 * * *": async ({strapi}) => {
let threeDaysAgo = new Date();
let twentyNineDaysAgo = new Date() ;
threeDaysAgo.setDate(threeDaysAgo.getDate() - 3);
twentyNineDaysAgo.setDate(twentyNineDaysAgo.getDate() - 29);
console.log(threeDaysAgo, "Three days ago")
console.log(twentyNineDaysAgo, "Twenty Nine days ago");
const oldJobs = await strapi.entityService.findMany("api::job.job", {
filters: {
createdAt: {
$between: [threeDaysAgo.toISOString(), twentyNineDaysAgo.toISOString()],
}
},
});
console.log(oldJobs, "Old Jobs")
for (let job of oldJobs){
console.log(job)
await strapi.entityService.update("api::job.job",job.id, {
data:{
jobAge:{
set:[{id:2}]
},
}
})
}
},