From 7d1c346202bdc4724286759e3a9190656e124a46 Mon Sep 17 00:00:00 2001 From: Sander Date: Sat, 22 Jun 2024 15:53:54 +0200 Subject: [PATCH] fix: dont get points for joining your own fissa --- packages/api/src/service/BadgeService.ts | 12 +++++++++++- packages/api/src/service/FissaService.ts | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/api/src/service/BadgeService.ts b/packages/api/src/service/BadgeService.ts index ea41eb0..050e775 100644 --- a/packages/api/src/service/BadgeService.ts +++ b/packages/api/src/service/BadgeService.ts @@ -34,12 +34,22 @@ export class BadgeService extends ServiceWithContext { } } - async joinedFissa() { + async joinedFissa(pin: string) { const userId = this.session?.user.id if (!userId) return try { await this.db.$transaction(async transaction => { + const fissa = await transaction.fissa.findUnique({ + where: { pin }, + select: { by: { select: { accounts: { select: { userId: true } } } } } + }) + + if (fissa?.by?.accounts[0]?.userId === userId) { + return + } + + const point = await transaction.badges.findUnique({ where: { userId_name: { userId, name: BADGE.FISSAS_JOINED } } }) diff --git a/packages/api/src/service/FissaService.ts b/packages/api/src/service/FissaService.ts index 728e4e2..5055243 100644 --- a/packages/api/src/service/FissaService.ts +++ b/packages/api/src/service/FissaService.ts @@ -96,7 +96,7 @@ export class FissaService extends ServiceWithContext { create: { pin, userId }, update: {}, }); - await this.badgeService.joinedFissa() + await this.badgeService.joinedFissa(pin) } return fissa;