Skip to content

Commit

Permalink
fix(schedule): method not implemented in check premium users
Browse files Browse the repository at this point in the history
caused by UserRepository not returning the correct prisma object
  • Loading branch information
NedcloarBR committed Jun 1, 2024
1 parent 701bde5 commit 9c4239a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"editor.defaultFormatter": "Prisma.prisma",
"editor.formatOnSave": true
},
"material-icon-theme.activeIconPack": "nest",
"material-icon-theme.activeIconPack": "nest",
"material-icon-theme.files.associations": {
"*.controller.ts": "nest-controller",
"*.module.ts": "nest-module",
Expand All @@ -63,7 +63,6 @@
},

"cSpell.words": [
"N-D-B-Project",
"Autopost",
"autoposter",
"Awkword",
Expand All @@ -77,6 +76,7 @@
"cooldown",
"creaction",
"createreaction",
"crowdin",
"Decrementer",
"deezer",
"Deezer",
Expand Down Expand Up @@ -108,6 +108,7 @@
"moderacao",
"msgdm",
"msgint",
"N-D-B-Project",
"ndcash",
"necord",
"Necord",
Expand Down
2 changes: 1 addition & 1 deletion src/modules/database/repositories/User.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class UserRepository implements IUserRepository {
private readonly logger = new Logger(UserRepository.name);

public userSettings(): Prisma.UserSettingsDelegate<DefaultArgs> {
throw new Error("Method not implemented.");
return this.prisma.userSettings
}

public async get(userId: string): Promise<UserEntity> {
Expand Down
46 changes: 26 additions & 20 deletions src/modules/schedule/schedule.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,47 +19,53 @@ export class ScheduleService {

private readonly premiumUsers = ["330047048009252864", "463476708834803725"];

@Timeout(1000)
@Timeout(1000)
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
public async checkPermanentPremiumGuilds(): Promise<void> {
const startTimestamp = new Date().getMilliseconds();
this.logger.log("Start Checking Permanent Premium Guilds");
for (const guild of await this.database.GuildRepo().getAll()) {
if (this.premiumGuilds.includes(guild.id) && !guild.Settings.Premium) {
await this.database.GuildRepo().guildSettings().update({
where: {
guildId: guild.id,
},
data: {
Premium: true,
},
});
await this.database
.GuildRepo()
.guildSettings()
.update({
where: {
guildId: guild.id,
},
data: {
Premium: true,
},
});
}
}
const endTimestamp = new Date().getMilliseconds();
const time = endTimestamp - startTimestamp
const time = endTimestamp - startTimestamp;
this.logger.log(`Finished Checking Permanent Premium Guilds in ${time}ms`);
}

@Timeout(1000)
@Timeout(1000)
@Cron(CronExpression.EVERY_DAY_AT_MIDNIGHT)
public async checkPermanentPremiumUsers(): Promise<void> {
const startTimestamp = new Date().getMilliseconds();
this.logger.log("Start Checking Permanent Premium Users");
for (const user of await this.database.UserRepo().getAll()) {
if (this.premiumUsers.includes(user.id) && !user.Settings.Premium) {
await this.database.UserRepo().userSettings().update({
where: {
userId: user.id,
},
data: {
Premium: true,
},
});
await this.database
.UserRepo()
.userSettings()
.update({
where: {
userId: user.id,
},
data: {
Premium: true,
},
});
}
}
const endTimestamp = new Date().getMilliseconds();
const time = endTimestamp - startTimestamp;
const time = endTimestamp - startTimestamp;
this.logger.log(`Finished Checking Permanent Premium Users in ${time}ms`);
}
}

0 comments on commit 9c4239a

Please sign in to comment.