Skip to content

Commit

Permalink
fix reward limit (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joao Pedro da Silva authored Mar 29, 2023
1 parent 54ca2d3 commit 35ea42d
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 39 deletions.
1 change: 0 additions & 1 deletion packages/core/src/services/learnAndEarn/answer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ export async function answer(
const payments = await models.learnAndEarnPayment.sum('amount', {
where: {
levelId: lesson!.levelId,
status: 'paid'
}
});

Expand Down
38 changes: 1 addition & 37 deletions packages/core/src/services/learnAndEarn/claimRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ export async function registerClaimRewards(
}
);
}
// If the execution reaches this line, the transaction has been committed successfully
checkAvailableReward(levelId!)
})
.catch((error) => {
// If the execution reaches this line, an error occurred.
Expand All @@ -63,38 +61,4 @@ export async function registerClaimRewards(
});
});
return true;
}

const checkAvailableReward = async (levelId: number) => {
const level = await models.learnAndEarnLevel.findOne({
attributes: ['rewardLimit', 'totalReward'],
where: {
id: levelId,
}
});

if (!level?.rewardLimit) {
return;
}

const payments = await models.learnAndEarnPayment.sum('amount', {
where: {
levelId,
status: 'paid'
}
});

if (!payments) {
return;
}

if (level.rewardLimit <= (payments + level.totalReward)) {
// do not have funds to a next payment
await models.learnAndEarnPayment.destroy({
where: {
status: 'pending',
levelId,
}
});
}
}
}
1 change: 0 additions & 1 deletion packages/core/src/services/learnAndEarn/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ const getRewardAvailable = async (levelId: number): Promise<boolean> => {
const payments = await models.learnAndEarnPayment.sum('amount', {
where: {
levelId,
status: 'paid'
}
});

Expand Down

0 comments on commit 35ea42d

Please sign in to comment.