System Information
- Strapi Version: 3.5.1
- Operating System:
- Database: SQLlite
- Node Version: 12.8.4
- NPM Version:
- Yarn Version:
Hi,
Trying to add a cron task to automatically expire user accounts once the user reaches 30 years old.
I’m able to query the db and find the users but unable to update I get error message:-
(node:5954) UnhandledPromiseRejectionWarning: Error: The value of field: 'id', in your where filter, is undefined.
"*/2 * * * *": async () => {
//get todays date and work out over 30
const cutoffMax = new Date();
cutoffMax.setFullYear(cutoffMax.getFullYear() - 30);
//get all users who are older than max age
const youngsters = await strapi.plugins[
"users-permissions"
].services.user.fetchAll({
userStatus: "Subscribed",
dateOfBirth_lt: cutoffMax,
});
youngsters.forEach(async (member) => {
await strapi
.query("user", "users-permissions")
.update({ id: member.id }, { userStatus: "Expired" });
});
},
};