overhauled structure, leaderboardRoute.ts and userRoute.ts working
This commit is contained in:
parent
c2cd74ebe2
commit
fff55edf79
25 changed files with 315 additions and 212 deletions
|
|
@ -0,0 +1,29 @@
|
|||
import {TimeLeaderboardManager} from "../TimeLeaderboardManager.js";
|
||||
import {LeaderboardEntry, TimeLeaderboard} from "../../model/Leaderboard.js";
|
||||
import {Database} from "../../Database.js";
|
||||
|
||||
export class TimeLeaderboardPgPromiseManager extends TimeLeaderboardManager {
|
||||
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 deserialize(parsed: TimeLeaderboard): any {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
|
||||
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