Skip to content

Commit

Permalink
Add get leaderboard / experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Moschkin committed Nov 4, 2024
1 parent a55ac40 commit a08d33b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/controllers/api.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions app/logic/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,17 @@ export class ApiClass {
};
}

async loadEventLeaderboard(instance_id: number, max = 100): Promise<ApiResult> {
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<ApiResult> {

return {
Expand Down

0 comments on commit a08d33b

Please sign in to comment.