55 lines
1.7 KiB
JavaScript
55 lines
1.7 KiB
JavaScript
const ladderModel = require('./ladder.model');
|
|
const ladderService = require('./ladder.service');
|
|
const { UserModel } = require('../users/users.model');
|
|
|
|
// Get leaderboard
|
|
exports.getLeaderboard = async (req, res) => {
|
|
try {
|
|
const leaderboard = await ladderModel.getLeaderboard();
|
|
res.status(200).send(leaderboard);
|
|
} catch (error) {
|
|
console.error('Error getting leaderboard:', error);
|
|
res.status(500).send({ error: 'Failed to get leaderboard' });
|
|
}
|
|
};
|
|
|
|
// Get player's position in leaderboard
|
|
exports.getPlayerPosition = async (req, res) => {
|
|
try {
|
|
const { playerId } = req.params;
|
|
const position = await ladderModel.getPlayerPosition(playerId);
|
|
res.status(200).send({ position });
|
|
} catch (error) {
|
|
console.error('Error getting player position:', error);
|
|
res.status(500).send({ error: 'Failed to get player position' });
|
|
}
|
|
};
|
|
|
|
// Get player's rank info
|
|
exports.getPlayerRankInfo = async (req, res) => {
|
|
try {
|
|
const { playerId } = req.params;
|
|
const player = await UserModel.getById(playerId);
|
|
|
|
if (!player) {
|
|
return res.status(404).send({ error: 'Player not found' });
|
|
}
|
|
|
|
const rankInfo = ladderService.getPlayerRankInfo(player);
|
|
res.status(200).send(rankInfo);
|
|
} catch (error) {
|
|
console.error('Error getting player rank info:', error);
|
|
res.status(500).send({ error: 'Failed to get player rank info' });
|
|
}
|
|
};
|
|
|
|
// Get all rank configurations
|
|
exports.getRankConfigurations = async (req, res) => {
|
|
try {
|
|
const configs = ladderService.getAllRankConfigs();
|
|
res.status(200).send(configs);
|
|
} catch (error) {
|
|
console.error('Error getting rank configurations:', error);
|
|
res.status(500).send({ error: 'Failed to get rank configurations' });
|
|
}
|
|
}; |