DO - 16 랭킹 서버 수정

This commit is contained in:
Parkillhwan 2025-03-20 00:04:10 +09:00
parent a393930db7
commit c0e039f7f8
2 changed files with 6 additions and 4 deletions

2
app.js
View File

@ -75,7 +75,7 @@ app.use(express.static(path.join(__dirname, 'public')));
app.use('/', indexRouter);
app.use('/users', usersRouter);
app.use('/leaderboard', leaderboardRouter);
app.use('/', leaderboardRouter);
app.use('/coins', coinsRouter);
// catch 404 and forward to error handler

View File

@ -3,7 +3,7 @@ const {ObjectId} = require("mongodb");
var router = express.Router();
// 랭킹 조회
router.get("/", async function (req, res, next) {
router.get("/leaderboard", async function (req, res, next) {
try {
if(!req.session.isAuthenticated) {
return res.status(403).send("로그인이 필요합니다.");
@ -35,7 +35,7 @@ router.get("/", async function (req, res, next) {
lose: user.lose || 0,
winRate: parseFloat(winRate.toFixed(2)), // 소수점 2자리까지 표시
totalGames: totalGames,
imageIndex: user.profileImageIndex,
profileImageIndex: user.profileImageIndex,
};
})
.sort((a, b) => {
@ -46,9 +46,11 @@ router.get("/", async function (req, res, next) {
return b.winRate - a.winRate; // 승률 내림차순 정렬
});
console.log(userRating);
console.log(result);
res.json({
rating: userRating,
leaderboardDatas : result ?? []
scoreInfos : result ?? []
});
} catch(err) {
console.error(err);