Skip to content

Commit

Permalink
feat: check if has users or guilds in database before checking premium
Browse files Browse the repository at this point in the history
  • Loading branch information
NedcloarBR committed Jul 14, 2024
1 parent 9804b7b commit 99016d3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/modules/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { Services } from "@/types/Constants";
import { Inject, Injectable, Logger } from "@nestjs/common";
import { Cron, CronExpression, Timeout } from "@nestjs/schedule";
import { PrismaService } from "nestjs-prisma";
import { IDatabaseService } from "../database/interfaces/IDatabaseService";

@Injectable()
export class ScheduleService {
public constructor(@Inject(Services.Database) private readonly database: IDatabaseService) {}
public constructor(
@Inject(Services.Database) private readonly database: IDatabaseService,
private readonly prisma: PrismaService,
) {}

private readonly logger = new Logger(ScheduleService.name);

Expand All @@ -24,7 +28,12 @@ export class ScheduleService {
public async checkPermanentPremiumGuilds(): Promise<void> {
const startTimestamp = new Date().getMilliseconds();
this.logger.log("Started Checking Permanent Premium Guilds");
for (const guild of await this.database.GuildRepo().getAll()) {
const guilds = await this.database.GuildRepo().getAll();
if (!guilds) {
this.logger.log("There is no Guilds in database");
return;
}
for (const guild of guilds) {
if (this.premiumGuilds.includes(guild.id) && !guild.Settings.Premium) {
await this.database
.GuildRepo()
Expand All @@ -49,7 +58,14 @@ export class ScheduleService {
public async checkPermanentPremiumUsers(): Promise<void> {
const startTimestamp = new Date().getMilliseconds();
this.logger.log("Started Checking Permanent Premium Users");
for (const user of await this.database.UserRepo().getAll()) {

const users = await this.database.UserRepo().getAll();

if (!users) {
this.logger.log("There is no Uses in database");
return;
}
for (const user of users) {
if (this.premiumUsers.includes(user.id) && !user.Settings.Premium) {
await this.database
.UserRepo()
Expand Down

0 comments on commit 99016d3

Please sign in to comment.