From 7f2ce77229bde5e4044b169cde379673e79dcb83 Mon Sep 17 00:00:00 2001 From: Peter Date: Sat, 29 Jun 2024 08:24:35 +0200 Subject: [PATCH] Fix bug in discord model and invite quests --- apps/api/src/app/models/DiscordGuild.ts | 31 +++++++++++++------ .../src/app/services/QuestInviteService.ts | 4 +-- apps/api/src/app/services/QuestService.ts | 8 ++--- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/apps/api/src/app/models/DiscordGuild.ts b/apps/api/src/app/models/DiscordGuild.ts index f0ebbdd34..1db3fbc2c 100644 --- a/apps/api/src/app/models/DiscordGuild.ts +++ b/apps/api/src/app/models/DiscordGuild.ts @@ -9,20 +9,33 @@ export const DiscordGuild = mongoose.model( sub: String, poolId: String, guildId: String, - // channelId: String, adminRoleId: String, name: String, secret: String, notifications: { - questCreate: { - isEnabled: Boolean, - message: String, - channelId: String, + type: { + questCreate: { + isEnabled: Boolean, + message: String, + channelId: String, + }, + questEntryCreate: { + isEnabled: Boolean, + message: String, + channelId: String, + }, }, - questEntryCreate: { - isEnabled: Boolean, - message: String, - channelId: String, + default: { + questCreate: { + isEnabled: false, + message: '', + channelId: '', + }, + questEntryCreate: { + isEnabled: false, + message: '', + channelId: '', + }, }, }, }, diff --git a/apps/api/src/app/services/QuestInviteService.ts b/apps/api/src/app/services/QuestInviteService.ts index e84e4c3ea..e72bcc620 100644 --- a/apps/api/src/app/services/QuestInviteService.ts +++ b/apps/api/src/app/services/QuestInviteService.ts @@ -106,13 +106,13 @@ export default class QuestInviteService implements IQuestService { // Iterate over invite quests and assert if all quests for this invite quest have been completed for (const inviteQuest of inviteQuests) { - // Search for a single required quest entry by another user and continue if it already exists + // Search for a single required quest entry by another user and continue if it does not exist const Entry = serviceMap[inviteQuest.requiredQuest.variant].models.entry; const requiredQuestEntry = await Entry.findOne({ questId: inviteQuest.requiredQuest.questId, sub: account.sub, }); - if (requiredQuestEntry) continue; + if (!requiredQuestEntry) continue; // If the participant has received the invite quest bonus already continue const inviteQuestEntry = await QuestInviteEntry.findOne({ diff --git a/apps/api/src/app/services/QuestService.ts b/apps/api/src/app/services/QuestService.ts index f5223a065..a65604edc 100644 --- a/apps/api/src/app/services/QuestService.ts +++ b/apps/api/src/app/services/QuestService.ts @@ -16,7 +16,6 @@ import AccountProxy from '../proxies/AccountProxy'; import ParticipantService from './ParticipantService'; import THXService from './THXService'; -const InviteService = serviceMap[QuestVariant.Invite] as IInviteService; export default class QuestService { static async count({ poolId }) { const variants = Object.keys(QuestVariant).filter((v) => !isNaN(Number(v))); @@ -208,9 +207,6 @@ export default class QuestService { const isAvailable = await this.isAvailable(variant, { quest, account, data }); if (!isAvailable.result) throw new Error(isAvailable.reason); - // Assert if a required quest for invite quests has been completed - await InviteService.assertQuestEntry({ pool, quest, account }); - // Create the quest entry const entry = await Entry.create({ ...data, @@ -222,6 +218,10 @@ export default class QuestService { } as TQuestEntry); if (!entry) throw new Error('Entry creation failed.'); + // Assert if a required quest for invite quests has been completed + const InviteService = serviceMap[QuestVariant.Invite] as IInviteService; + await InviteService.assertQuestEntry({ pool, quest, account }); + // Add points to participant balance await PointBalanceService.add(pool, account, amount);