JaBa/helpers/clearTransactions.js

18 lines
621 B
JavaScript
Raw Normal View History

module.exports.init = async function (client) {
setInterval(async () => {
// Date.now() + days * hours * mins * secs * msecs / 1 month
const timestamp = Date.now() + 30 * 24 * 60 * 60 * 1000;
const members = client.membersData.find({ transactions: { $gt: [] } });
2022-07-02 01:17:00 +05:00
for (const member of members) {
const transactions = member.transactions;
for await (const transaction of transactions) {
if (transaction.date < timestamp) {
const index = transactions.indexOf(transaction);
transactions.splice(index, 1);
await member.save();
2022-07-02 01:17:00 +05:00
}
}
}
}, 7 * 24 * 60 * 60 * 1000); // every 7 days
2022-07-02 01:17:00 +05:00
};