diff --git a/app/controllers/api.controller.ts b/app/controllers/api.controller.ts index 11da2ae..a86c9ba 100644 --- a/app/controllers/api.controller.ts +++ b/app/controllers/api.controller.ts @@ -52,7 +52,23 @@ router.get('/profile', async (req: Request, res: Response, next) => { } }); +router.get('/leaderboard', async (req: Request, res: Response, next) => { + if (!req.query || !req.query.instance_id) { + res.status(400).send('Whaat?'); + return; + } + + try { + const instance_id = Number(req.query.instance_id); + const max = req.query.max ? Number(req.query.max) : 100; + let apiResult = await DataCoreAPI.loadEventLeaderboard(instance_id, max); + res.status(apiResult.Status).send(apiResult.Body); + } + catch (e) { + next(e); + } +}); router.post('/login', async (req: Request, res: Response, next) => { if (!req.body || !req.body.user || !req.body.password) { diff --git a/app/logic/api.ts b/app/logic/api.ts index 307080c..4681b15 100644 --- a/app/logic/api.ts +++ b/app/logic/api.ts @@ -201,6 +201,17 @@ export class ApiClass { }; } + async loadEventLeaderboard(instance_id: number, max = 100): Promise { + let response = await fetch( + `https://app.startrektimelines.com/event/leaderboard?access_token=${this._stt_token}&instance_id=${instance_id}&max=${max}`, + ).then(this.checkSTTResponse.bind(this)).then(res => res.json()); + + return { + Status: 200, + Body: response + } + } + async loadFleetInfo(fleetId: string, logData: LogData, username?: string, password?: string, access_token?: string): Promise { return {