xyter/src/jobs/shop/modules/roles/index.ts
2022-06-11 19:45:07 +02:00

32 lines
831 B
TypeScript

import { Client } from "discord.js";
import { IShopRole } from "../../../../interfaces/ShopRole";
import shopRoleSchema from "../../../../models/shopRole";
import * as overDueForPayment from "./components/overDueForPayment";
import * as dueForPayment from "./components/dueForPayment";
export const execute = async (client: Client) => {
const roles = await shopRoleSchema.find();
await Promise.all(
roles.map(async (role: IShopRole) => {
const { lastPayed } = role;
const nextPayment = new Date(
lastPayed.setHours(lastPayed.getHours() + 1)
);
const now = new Date();
if (nextPayment > now) {
await dueForPayment.execute(client, role);
return;
}
if (nextPayment < now) {
await overDueForPayment.execute(client, role);
}
})
);
};