mirror of
https://github.com/psforever/PSFPortal.git
synced 2026-02-23 00:23:38 +00:00
leaderboard and weapon stats
This commit is contained in:
parent
bd5e3c9043
commit
67708b166d
7 changed files with 528 additions and 0 deletions
21
api/db.js
21
api/db.js
|
|
@ -70,6 +70,16 @@ export const AVATAR = Object.freeze({
|
|||
CEP: Symbol("cep"),
|
||||
});
|
||||
|
||||
export const WEAPONSTAT = Object.freeze({
|
||||
THIS: Symbol("weapon"),
|
||||
ID: Symbol("avatar_id"),
|
||||
WEAPON: Symbol("weapon_id"),
|
||||
SHOTS_FIRED: Symbol("shots_fired"),
|
||||
SHOTS_LANDED: Symbol("shots_landed"),
|
||||
KILLS: Symbol("kills"),
|
||||
ASSISTS: Symbol("assists")
|
||||
});
|
||||
|
||||
export const LOGIN = Object.freeze({
|
||||
THIS: Symbol("login"),
|
||||
ID: Symbol("id"),
|
||||
|
|
@ -322,6 +332,17 @@ export async function get_character_batch_for_stats(batch, sort, order) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function get_weaponstats_by_avatar(id) {
|
||||
try {
|
||||
const weapons = await pool.query('SELECT * FROM weaponstat WHERE avatar_id=$1 ORDER BY kills DESC', [id])
|
||||
return weapons.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])
|
||||
|
|
|
|||
12
api/user.js
12
api/user.js
|
|
@ -62,4 +62,16 @@ api.get('/user/:user/logins', NEED_SESSION, async (req, res, next) => {
|
|||
}
|
||||
});
|
||||
|
||||
api.get('/avatar/:avatar/weaponstats', async (req, res, next) => {
|
||||
const avatar = req.params.avatar;
|
||||
|
||||
try {
|
||||
const weapons = await db.get_weaponstats_by_avatar(avatar);
|
||||
res.status(200).json({ weapons: weapons });
|
||||
} catch (e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default api;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue