Skip to content

Commit

Permalink
fix(api): ms trophy validation (freeCodeCamp#53978)
Browse files Browse the repository at this point in the history
  • Loading branch information
moT01 authored Mar 5, 2024
1 parent a8ce82f commit 87351f3
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions api-server/src/server/boot/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -766,26 +766,26 @@ function createMsTrophyChallengeCompleted(app) {

const { userId } = msProfileJson;

const msGameStatusApi = `https://learn.microsoft.com/api/gamestatus/${userId}`;
const msGameStatusApiRes = await fetch(msGameStatusApi);
const msGameStatusJson = await msGameStatusApiRes.json();
const msUserAchievementsApi = `https://learn.microsoft.com/api/achievements/user/${userId}`;
const msUserAchievementsApiRes = await fetch(msUserAchievementsApi);
const msUserAchievementsJson = await msUserAchievementsApiRes.json();

if (!msGameStatusApiRes.ok) {
if (!msUserAchievementsApiRes.ok) {
return res.status(403).json({
type: 'error',
message: 'flash.ms.trophy.err-3'
});
}

if (msGameStatusJson.achievements?.length === 0) {
if (msUserAchievementsJson.achievements?.length === 0) {
return res.status(403).json({
type: 'error',
message: 'flash.ms.trophy.err-6'
});
}

const hasEarnedTrophy = msGameStatusJson.achievements?.some(
a => a.awardUid === msTrophyId
const hasEarnedTrophy = msUserAchievementsJson.achievements?.some(
a => a.typeId === msTrophyId
);

if (!hasEarnedTrophy) {
Expand All @@ -800,7 +800,7 @@ function createMsTrophyChallengeCompleted(app) {

const completedChallenge = pick(body, ['id']);

completedChallenge.solution = msGameStatusApi;
completedChallenge.solution = msUserAchievementsApi;
completedChallenge.completedDate = Date.now();

try {
Expand Down

0 comments on commit 87351f3

Please sign in to comment.