add player tracked since date
All checks were successful
Deploy Backend / deploy (push) Successful in 3m6s

This commit is contained in:
Lee 2024-10-09 15:25:21 +01:00
parent 6b8244fa48
commit ee042fe91e
3 changed files with 22 additions and 1 deletions

View File

@ -0,0 +1,10 @@
import { HttpCode } from "../common/http-codes";
export class InternalServerError extends Error {
constructor(
public message: string = "internal-server-error",
public status: number = HttpCode.INTERNAL_SERVER_ERROR.code
) {
super(message);
}
}

View File

@ -20,9 +20,18 @@ export class Player {
@prop()
private statisticHistory?: Record<string, PlayerHistory>;
/**
* The date the player was last tracked.
*/
@prop()
public lastTracked?: Date;
/**
* The date the player was first tracked.
*/
@prop()
public trackedSince?: Date;
/**
* Gets the player's statistic history.
*/

View File

@ -5,6 +5,7 @@ import { app } from "../index";
import { getDaysAgoDate, getMidnightAlignedDate } from "@ssr/common/utils/time-utils";
import { scoresaberService } from "@ssr/common/service/impl/scoresaber";
import ScoreSaberPlayerToken from "@ssr/common/types/token/scoresaber/score-saber-player-token";
import { InternalServerError } from "../error/internal-server-error";
export class PlayerService {
/**
@ -49,8 +50,9 @@ export class PlayerService {
console.log(`Creating player "${id}"...`);
player = (await PlayerModel.create({ _id: id })) as any;
if (player === null) {
throw new NotFoundError(`Player "${id}" not found`);
throw new InternalServerError(`Failed to create player document for "${id}"`);
}
player.trackedSince = new Date();
await this.seedPlayerHistory(player, playerToken);
console.log(`Created player "${id}".`);
} else {