add kills and tidy up

This commit is contained in:
ScrawnyRonnie 2024-03-18 21:15:42 -04:00
parent 67708b166d
commit d6c50014dc
4 changed files with 147 additions and 41 deletions

View file

@ -80,6 +80,11 @@ export const WEAPONSTAT = Object.freeze({
ASSISTS: Symbol("assists")
});
export const KILLACTIVITY = Object.freeze({
THIS: Symbol("kill"),
ID: Symbol("killer_id"),
});
export const LOGIN = Object.freeze({
THIS: Symbol("login"),
ID: Symbol("id"),
@ -343,6 +348,21 @@ export async function get_weaponstats_by_avatar(id) {
}
}
export async function get_killstats() {
try {
const kills = await pool.query('SELECT count(killactivity.killer_id), killactivity.killer_id, avatar.name, avatar.bep, avatar.cep, avatar.faction_id' +
' FROM killactivity' +
' INNER JOIN avatar ON killactivity.killer_id = avatar.id' +
' GROUP BY killactivity.killer_id, avatar.name, avatar.bep, avatar.cep, avatar.faction_id' +
' ORDER BY count(killer_id) DESC')
return kills.rows;
} catch (e) {
if (e.code)
e.code = pg_error_inv[e.code]
throw e;
}
}
export async function get_characters_by_account(account_id) {
try {
const characters = await pool.query('SELECT * FROM avatar WHERE account_id=$1 AND deleted=false', [account_id])

View file

@ -58,4 +58,14 @@ api.get('/char_stats_cep/:batch', async (req, res, next) => {
}
});
api.get('/char_stats_kills', async (req, res, next) => {
try {
const kills = await db.get_killstats();
res.status(200).json({ kills: kills });
} catch (e) {
console.log(e);
res.status(500).json({ message: 'error' });
}
});
export default api;