use type for tracked status
All checks were successful
Deploy / deploy (push) Successful in 2m32s

This commit is contained in:
Lee 2024-09-28 14:51:17 +01:00
parent 6b02a0f139
commit 04dda00b7f
3 changed files with 18 additions and 6 deletions

@ -1,6 +1,7 @@
import { NextRequest, NextResponse } from "next/server";
import { connectMongo } from "@/common/mongo";
import { IPlayer, PlayerModel } from "@/common/schema/player-schema";
import { PlayerTrackedSince } from "@/common/player/player-tracked-since";
export async function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id");
@ -13,7 +14,7 @@ export async function GET(request: NextRequest) {
await connectMongo(); // Connect to Mongo
const foundPlayer: IPlayer | null = await PlayerModel.findById(id);
const response: { tracked: boolean; trackedSince?: string } = {
const response: PlayerTrackedSince = {
tracked: foundPlayer != null,
};
if (foundPlayer != null) {

@ -0,0 +1,11 @@
export interface PlayerTrackedSince {
/**
* Whether the player statistics are being tracked
*/
tracked: boolean;
/**
* The date the player was first tracked
*/
trackedSince?: string;
}

@ -7,6 +7,7 @@ import { config } from "../../../config";
import Tooltip from "@/components/tooltip";
import { InformationCircleIcon } from "@heroicons/react/16/solid";
import { format } from "@formkit/tempo";
import { PlayerTrackedSince } from "@/common/player/player-tracked-since";
type Props = {
player: ScoreSaberPlayer;
@ -17,10 +18,9 @@ export default function PlayerTrackedStatus({ player }: Props) {
queryKey: ["playerIsBeingTracked", player.id],
queryFn: () =>
ky
.get<{
tracked: boolean;
trackedSince: string;
}>(`${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`)
.get<PlayerTrackedSince>(
`${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`,
)
.json(),
});
@ -34,7 +34,7 @@ export default function PlayerTrackedStatus({ player }: Props) {
display={
<div className="flex flex-col justify-center items-center">
<p>This player is having their statistics tracked!</p>
<p>Tracked Since: {format(data.trackedSince)}</p>
<p>Tracked Since: {format(data.trackedSince!)}</p>
</div>
}
side="bottom"