Skip to content

Commit

Permalink
Merge pull request #4 from MoniswapFi/dev
Browse files Browse the repository at this point in the history
Fix: quest API update
  • Loading branch information
ryy197340 authored Sep 16, 2024
2 parents 24370b6 + c1b0ab3 commit 38b411c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/controller/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports.getVerifiedCount = async function (req, res) {

exports.getAllLists = async function (req, res) {
try {
const wallets = await WalletModel.find({}).select("-_id -__v");
const wallets = await WalletModel.find({}).select("-_id -__v").sort('-points');

const results = await Promise.all(
wallets.map(async (wallet) => {
Expand All @@ -37,8 +37,6 @@ exports.getAllLists = async function (req, res) {
})
);

results.sort((a, b) => b.leaderboardCount - a.leaderboardCount);

return res.status(200).json(results);
} catch (error) {
return res.status(500).json({ error: error.message });
Expand Down
13 changes: 10 additions & 3 deletions src/controller/quest.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ exports.create = async function (req, res) {
return res.status(400).json({ error: "Invalid request params" });
}

await QuestModel.findOneAndUpdate(
const result = await QuestModel.findOneAndUpdate(
{ address: requestBody.address, reason: requestBody.reason },
{
address: requestBody.address,
reason: requestBody.reason,
points: requestBody.points,
},
{ upsert: true }
{ upsert: true, includeResultMetadata: true }
);

const count = await QuestModel.countDocuments({ address: requestBody.address });
if (count === 11) {
if (count === 11 && result && !result.value) {
const wallet = await WalletModel.findOne(
{
address: requestBody.address,
Expand All @@ -48,6 +48,13 @@ exports.create = async function (req, res) {
},
{ upsert: true }
);

const result = await LeaderboardModel.countDocuments({ referrer: wallet.referrer });
if (result === 1) {
await WalletModel.findOneAndUpdate({ address: wallet.referrer }, { $inc: { points: 200 } });
} else if (result > 1) {
await WalletModel.findOneAndUpdate({ address: wallet.referrer }, { $inc: { points: 400 } });
}
}
}

Expand Down

0 comments on commit 38b411c

Please sign in to comment.