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 { NextRequest, NextResponse } from "next/server";
import { connectMongo } from "@/common/mongo"; import { connectMongo } from "@/common/mongo";
import { IPlayer, PlayerModel } from "@/common/schema/player-schema"; import { IPlayer, PlayerModel } from "@/common/schema/player-schema";
import { PlayerTrackedSince } from "@/common/player/player-tracked-since";
export async function GET(request: NextRequest) { export async function GET(request: NextRequest) {
const id = request.nextUrl.searchParams.get("id"); const id = request.nextUrl.searchParams.get("id");
@ -13,7 +14,7 @@ export async function GET(request: NextRequest) {
await connectMongo(); // Connect to Mongo await connectMongo(); // Connect to Mongo
const foundPlayer: IPlayer | null = await PlayerModel.findById(id); const foundPlayer: IPlayer | null = await PlayerModel.findById(id);
const response: { tracked: boolean; trackedSince?: string } = { const response: PlayerTrackedSince = {
tracked: foundPlayer != null, tracked: foundPlayer != null,
}; };
if (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 Tooltip from "@/components/tooltip";
import { InformationCircleIcon } from "@heroicons/react/16/solid"; import { InformationCircleIcon } from "@heroicons/react/16/solid";
import { format } from "@formkit/tempo"; import { format } from "@formkit/tempo";
import { PlayerTrackedSince } from "@/common/player/player-tracked-since";
type Props = { type Props = {
player: ScoreSaberPlayer; player: ScoreSaberPlayer;
@ -17,10 +18,9 @@ export default function PlayerTrackedStatus({ player }: Props) {
queryKey: ["playerIsBeingTracked", player.id], queryKey: ["playerIsBeingTracked", player.id],
queryFn: () => queryFn: () =>
ky ky
.get<{ .get<PlayerTrackedSince>(
tracked: boolean; `${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`,
trackedSince: string; )
}>(`${config.siteUrl}/api/player/isbeingtracked?id=${player.id}`)
.json(), .json(),
}); });
@ -34,7 +34,7 @@ export default function PlayerTrackedStatus({ player }: Props) {
display={ display={
<div className="flex flex-col justify-center items-center"> <div className="flex flex-col justify-center items-center">
<p>This player is having their statistics tracked!</p> <p>This player is having their statistics tracked!</p>
<p>Tracked Since: {format(data.trackedSince)}</p> <p>Tracked Since: {format(data.trackedSince!)}</p>
</div> </div>
} }
side="bottom" side="bottom"