Skip to content

Commit

Permalink
feat: allow ignoring users tiers from being automatically set
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Nov 29, 2024
1 parent 626e1f6 commit 0af3d2b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions apps/tasks/src/jobs/refreshPatrons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export default class RefreshPatrons extends TaskJob {

// Reset rewards tier
const user = await prisma.user.findFirst({ where: { patronId: dbPatron.id } });
if (user && !patreonConfig.skipUsers.includes(user.id)) {
if (user && !patreonConfig.skipUsers.includes(user.id) && !user.tierManuallySet) {
this.logger.info(`Resetting rewards for user ${user.id}`);
operations.push(prisma.user.update({ where: { id: user.id }, data: { rewardTier: 0, driveEnabled: false } }));
}
Expand Down Expand Up @@ -227,7 +227,7 @@ export default class RefreshPatrons extends TaskJob {
// Upsert in user table
if (patron.discordId) {
const user = await prisma.user.findFirst({ where: { patronId: patron.id } });
if (user && user.id !== patron.discordId && !patreonConfig.skipUsers.includes(user.id)) {
if (user && user.id !== patron.discordId && !patreonConfig.skipUsers.includes(user.id) && !user.tierManuallySet) {
this.logger.info(`Removing patronage for ${user.id} due to clashing with ${patron.discordId} (${patron.id})`);
operations.push(prisma.user.update({ where: { id: user.id }, data: { patronId: undefined, rewardTier: 0, driveEnabled: false } }));
}
Expand All @@ -244,7 +244,7 @@ export default class RefreshPatrons extends TaskJob {
} else if (!patreonConfig.skipUsers.includes(patron.id)) {
// Find if this person is a patron, and give them a tier if so
const user = await prisma.user.findFirst({ where: { patronId: patron.id } });
if (!user || patreonConfig.skipUsers.includes(user.id)) continue;
if (!user || user.tierManuallySet || patreonConfig.skipUsers.includes(user.id)) continue;
const tier = this.determineRewardTier(patron);
if (user.rewardTier === tier) continue;
this.logger.log(`Updating user ${user.id} reward tier for patron ${patron.id} (${patron.name}, tier=${tier})`);
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"sync:dev": "yarn manypkg run bot sync:dev",
"run-job": "yarn manypkg run tasks run-job",
"prisma:generate": "prisma generate && yarn manypkg run bot prisma:generate && yarn manypkg run dashboard prisma:generate && yarn manypkg run tasks prisma:generate",
"prisma:deploy": "prisma migrate deploy"
"prisma:deploy": "prisma migrate deploy",
"prisma:dev": "prisma migrate dev"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "tierManuallySet" BOOLEAN NOT NULL DEFAULT false;
5 changes: 3 additions & 2 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ datasource db {
model User {
id String @id
rewardTier Int @default(0)
patronId String?
rewardTier Int @default(0)
patronId String?
tierManuallySet Boolean @default(false)
webapp Boolean @default(false)
Expand Down

0 comments on commit 0af3d2b

Please sign in to comment.