add tracked since to the schema
Some checks failed
Deploy / deploy (push) Has been cancelled

This commit is contained in:
Lee 2024-09-28 14:43:21 +01:00
parent a3392ca468
commit 53b51582b2
3 changed files with 14 additions and 2 deletions

@ -23,6 +23,7 @@ export async function GET(request: NextRequest) {
if (shouldCreatePlayer && foundPlayer == null) {
foundPlayer = await PlayerModel.create({
_id: id,
trackedSince: new Date(),
});
const response = await scoresaberService.lookupPlayer(id, true);
if (response != undefined) {

@ -14,7 +14,12 @@ export async function GET(request: NextRequest) {
// Fetch the player and return their statistic history
let foundPlayer: IPlayer | null = await PlayerModel.findById(id);
return NextResponse.json({
const response: { tracked: boolean; lastTracked?: string } = {
tracked: foundPlayer != null,
});
};
if (foundPlayer != null) {
response["lastTracked"] = foundPlayer.trackedSince?.toUTCString();
}
return NextResponse.json(response);
}

@ -25,6 +25,11 @@ export interface IPlayer extends Document {
*/
rawPlayer: ScoreSaberPlayer;
/**
* The first time the player was tracked
*/
trackedSince: Date;
/**
* Gets when this player was last tracked.
*/
@ -62,6 +67,7 @@ const PlayerSchema = new Schema<IPlayer>({
lastTracked: { type: Date, default: new Date(), required: false },
rawPlayer: { type: Object, required: false },
statisticHistory: { type: Map, default: () => new Map(), required: false },
trackedSince: { type: Date, default: new Date(), required: false },
});
PlayerSchema.methods.getLastTracked = function (): Date {