migrate around me to the backend

This commit is contained in:
Lee
2024-10-19 04:53:06 +01:00
parent 7421c47959
commit c40b8b5d8e
10 changed files with 123 additions and 92 deletions

View File

@ -1,6 +1,8 @@
import { PlayerHistory } from "../player/player-history";
import { kyFetch } from "./utils";
import { Config } from "../config";
import { AroundPlayer } from "../types/around-player";
import { AroundPlayerResponse } from "../response/around-player-response";
/**
* Sorts the player history based on date,
@ -22,3 +24,13 @@ export function sortPlayerHistory(history: Map<string, PlayerHistory>) {
export async function trackPlayer(id: string) {
await kyFetch(`${Config.apiUrl}/player/history/${id}?createIfMissing=true`);
}
/**
* Gets the players around a player.
*
* @param id the player to get around
* @param type the type to get
*/
export async function getPlayersAroundPlayer(id: string, type: AroundPlayer) {
return await kyFetch<AroundPlayerResponse>(`${Config.apiUrl}/player/around/${id}/${type}`);
}

View File

@ -28,10 +28,10 @@ export function delay(ms: number) {
*
* @param rank the rank
* @param itemsPerPage the items per page
* @returns the page
* @returns the page number
*/
export function getPageFromRank(rank: number, itemsPerPage: number) {
return Math.floor(rank / itemsPerPage) + 1;
return Math.floor((rank - 1) / itemsPerPage) + 1;
}
/**