-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a7ab771
commit 5ca53a7
Showing
6 changed files
with
46 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getAchievement } from "../utils/AchievementCalculator" | ||
import { Challenge } from "../models"; | ||
|
||
const getRanking = async function(req, res, next){ | ||
const id = req.params.challengeId; | ||
const challenge = await Challenge.findOne({ where: { id: id } }); | ||
if (challenge) { | ||
const ranks = await Ranking(challenge); | ||
res.send({ data: { | ||
ranks: ranks | ||
}}); | ||
} | ||
else { | ||
next(new NotFoundChallengeError('존재하지 않는 challenge')); | ||
return; | ||
} | ||
} | ||
|
||
const Ranking = async (challenge) => { | ||
const baseChallenge = await challenge.getBaseChallenge(); | ||
const challenges = await baseChallenge.getChallenges({ include: ['user'] }); | ||
const achivements = await Promise.all(challenges.map(async (item) => { | ||
const userAchivement = await getAchievement(item, item.user); | ||
return { | ||
user: item.user, | ||
achivement: userAchivement, | ||
} | ||
})) | ||
return achivements.sort((a, b) => b.achivement - a.achivement) | ||
} | ||
|
||
export { | ||
getRanking | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Router } from 'express'; | ||
import { getRanking } from '../controllers/RankingController'; | ||
|
||
const router = Router(); | ||
|
||
router.get('/challenge/:challengeId', getRanking); | ||
|
||
export default router; |
This file was deleted.
Oops, something went wrong.