I want to create a Strapi cron job but I have a problem when I try to get the list of users.
That’s how looks my server.js file:
const cronTasks = require("./cron-tasks");
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
app: {
keys: env.array('APP_KEYS'),
},
cron: {
enabled: true,
tasks: cronTasks,
},
});
And that’s how looks my cron-tasks.js file:
module.exports = {
'*/5 * * * * *': async ({strapi}) => {
try {
const users = await strapi.service("plugin::users-permissions.user").find();
console.log(users);
} catch (error) {
console.log(error)
}
},
};
And my error:
strapi.service(...).find is not a function
What should I change?
2
Answers
worked with await strapi.entityService.findMany('plugin::users-permissions.user');
Could you try with
strapi.db.query('plugin::users-permissions.user').find()
?