File size: 988 Bytes
183a3de | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | import { connection, NAME_TABLE_PLAYERS } from './index.js';
import Big from 'big.js';
export async function getTopPlayers() {
try {
// Lấy tất cả người chơi
const [rows] = await connection.execute(
`SELECT idUserZalo, playerName, balance FROM ${NAME_TABLE_PLAYERS}`
);
// Chuyển đổi balance sang Big và sắp xếp lại
const sortedPlayers = rows
.map(player => ({
idUser: player.idUserZalo,
playerName: player.playerName,
balance: new Big(player.balance)
}))
.sort((a, b) => b.balance.minus(a.balance))
.slice(0, 20) // Lấy top 20
.map((player, index) => ({
rank: index + 1,
idUser: player.idUser,
playerName: player.playerName,
balance: player.balance.toString()
}));
return sortedPlayers;
} catch (error) {
console.error('Lỗi khi lấy danh sách top người chơi:', error);
return [];
}
}
|