Skip to content

Commit

Permalink
change track to post
Browse files Browse the repository at this point in the history
  • Loading branch information
RealFascinated committed Nov 18, 2024
1 parent a59ce3f commit c141fba
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 15 deletions.
4 changes: 2 additions & 2 deletions projects/backend/src/controller/player.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get } from "elysia-decorators";
import { Controller, Get, Post } from "elysia-decorators";
import { PlayerService } from "../service/player.service";
import { t } from "elysia";
import { PlayerTrackedSince } from "@ssr/common/player/player-tracked-since";
Expand Down Expand Up @@ -32,7 +32,7 @@ export default class PlayerController {
return superJson ? SuperJSON.stringify(player) : player;
}

@Get("/track/:id", {
@Post("/track/:id", {
config: {},
params: t.Object({
id: t.String({ required: true }),
Expand Down
22 changes: 11 additions & 11 deletions projects/common/src/utils/player-utils.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {PlayerHistory} from "../player/player-history";
import {kyFetchJson, kyFetchText} from "./utils";
import {Config} from "../config";
import {AroundPlayer} from "../types/around-player";
import {AroundPlayerResponse} from "../response/around-player-response";
import { PlayerHistory } from "../player/player-history";
import { kyFetchJson, kyFetchText, kyPostJson } from "./utils";
import { Config } from "../config";
import { AroundPlayer } from "../types/around-player";
import { AroundPlayerResponse } from "../response/around-player-response";
import ScoreSaberPlayer from "../player/impl/scoresaber-player";
import {formatDateMinimal, getMidnightAlignedDate} from "./time-utils";
import {PpBoundaryResponse} from "../response/pp-boundary-response";
import {PlayedMapsCalendarResponse} from "../response/played-maps-calendar-response";
import {ScoreSaberScore} from "../model/score/impl/scoresaber-score";
import {Page} from "../pagination";
import { formatDateMinimal, getMidnightAlignedDate } from "./time-utils";
import { PpBoundaryResponse } from "../response/pp-boundary-response";
import { PlayedMapsCalendarResponse } from "../response/played-maps-calendar-response";
import { ScoreSaberScore } from "../model/score/impl/scoresaber-score";
import { Page } from "../pagination";
import SuperJSON from "superjson";

/**
Expand Down Expand Up @@ -53,7 +53,7 @@ export function getValueFromHistory(history: PlayerHistory, field: string): numb
* @param playerId the player id
*/
export async function trackPlayer(playerId: string) {
await kyFetchJson(`${Config.apiUrl}/player/track/${playerId}`);
await kyPostJson(`${Config.apiUrl}/player/track/${playerId}`);
}

/**
Expand Down
18 changes: 16 additions & 2 deletions projects/common/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ky from "ky";
import {formatNumberWithCommas, formatPp} from "./number-utils";
import {KyOptions} from "ky/distribution/types/options";
import { formatNumberWithCommas, formatPp } from "./number-utils";
import { KyOptions } from "ky/distribution/types/options";

/**
* Checks if we're in production
Expand Down Expand Up @@ -50,6 +50,20 @@ export async function kyFetchJson<T>(url: string, options?: KyOptions): Promise<
}
}

/**
* Posts data top the given url.
*
* @param url the url to post to
* @param options the ky options to use
*/
export async function kyPostJson<T>(url: string, options?: KyOptions): Promise<T | undefined> {
try {
return await ky.post<T>(url, options).json();
} catch (error) {
return undefined;
}
}

/**
* Fetches data from the given url.
*
Expand Down

0 comments on commit c141fba

Please sign in to comment.