Version 1.0: Funktioniere Bestenliste und sonst auch alles Funktionell

This commit is contained in:
2025-05-02 18:42:48 +02:00
parent b36d7a4274
commit a422ef879e
12 changed files with 124 additions and 1402 deletions
+56 -19
View File
@@ -10,6 +10,8 @@ class HighScoreRoute {
this.db = dbManager;
this.router.get("/", async (req, res) => await this.getHighscores(req, res));
this.router.get("/split/:count", async (req, res) => await this.getSplitedHighScores(req, res));
this.router.get("/count", async (req, res) => await this.getSplitedHighScoreCount(req, res));
}
/**@param {express.Request} req @param {express.Response} res*/
@@ -22,29 +24,64 @@ class HighScoreRoute {
}
for(const highscore of highscores){
const user1 = await this.db.usermanager.getUser({id: highscore.user1ID});
const user2 = await this.db.usermanager.getUser({id: highscore.user2ID});
const rang = highscores.indexOf(highscore) + 1;
returnJSON.scores.push({
id: highscore.id,
score: highscore.score,
rang: rang,
user1: {
id: user1.id,
username: user1.username,
fullName: user1.fullName
},
user2: {
id: user2.id,
username: user2.username,
fullName: user2.fullName
},
});
const highscoreJSON = await this.formatHighScore(highscore);
returnJSON.scores.push(highscoreJSON);
}
res.json(returnJSON);
}
/**@param {express.Request} req @param {express.Response} res*/
async getSplitedHighScores(req, res){
const count = req.params.count;
/** @type {Array<Score>} */
const highscores = await this.db.scoremanager.getSpiltedScore(count);
let returnJSON = {
scores: []
}
for(const highscore of highscores){
const highscoreJSON = await this.formatHighScore(highscore);
returnJSON.scores.push(highscoreJSON);
}
res.json(returnJSON);
}
/**@param {express.Request} req @param {express.Response} res*/
async getSplitedHighScoreCount(req, res){
const count = await this.db.scoremanager.getSplitedScoreCount();
res.json({
count: count
});
}
/** @param {Score} highscore */
async formatHighScore(highscore){
const user1 = await this.db.usermanager.getUser({id: highscore.user1ID});
const user2 = await this.db.usermanager.getUser({id: highscore.user2ID});
const rang = highscore.rank;
const returnJSON = {
id: highscore.id,
score: highscore.score,
rang: rang,
user1: {
id: user1.id,
username: user1.username,
fullName: user1.fullName
},
user2: {
id: user2.id,
username: user2.username,
fullName: user2.fullName
},
}
return returnJSON;
}
}
module.exports = HighScoreRoute;