Skip to content

Commit

Permalink
Fix bug in discord model and invite quests
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpolman committed Jun 29, 2024
1 parent d24b062 commit 7f2ce77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
31 changes: 22 additions & 9 deletions apps/api/src/app/models/DiscordGuild.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,33 @@ export const DiscordGuild = mongoose.model<DiscordGuildDocument>(
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: '',
},
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/services/QuestInviteService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down
8 changes: 4 additions & 4 deletions apps/api/src/app/services/QuestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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,
Expand All @@ -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);

Expand Down

0 comments on commit 7f2ce77

Please sign in to comment.