added /game/add, API hopefully finished
This commit is contained in:
parent
fff55edf79
commit
5f9a484285
19 changed files with 143 additions and 100 deletions
|
|
@ -0,0 +1,25 @@
|
|||
import {TimeLeaderboardRepository} from "../TimeLeaderboardRepository.js";
|
||||
import {LeaderboardEntry, TimeLeaderboard} from "../../model/Leaderboard.js";
|
||||
import {Database} from "../../Database.js";
|
||||
|
||||
export class TimeLeaderboardPgPromiseRepository extends TimeLeaderboardRepository {
|
||||
async getAll(): Promise<TimeLeaderboard> {
|
||||
const raw: any = await Database.db.manyOrNone(
|
||||
'SELECT * FROM lb_total_playtime INNER JOIN "user" ON user_id = id ORDER BY RANK;'
|
||||
);
|
||||
return this.serialize(raw);
|
||||
}
|
||||
|
||||
//region serialization
|
||||
protected serialize(raw: any): TimeLeaderboard {
|
||||
return raw.map((item) => {
|
||||
let newItem: LeaderboardEntry<string> = {
|
||||
rank: item.rank,
|
||||
username: item.name,
|
||||
score: item.total_playtime,
|
||||
}
|
||||
return newItem
|
||||
});
|
||||
}
|
||||
//endregion
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue