From ee042fe91e8b35e150ddd901f3e940012aa3b22e Mon Sep 17 00:00:00 2001 From: Liam Date: Wed, 9 Oct 2024 15:25:21 +0100 Subject: [PATCH] add player tracked since date --- projects/backend/src/error/internal-server-error.ts | 10 ++++++++++ projects/backend/src/model/player.ts | 9 +++++++++ projects/backend/src/service/player.service.ts | 4 +++- 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 projects/backend/src/error/internal-server-error.ts diff --git a/projects/backend/src/error/internal-server-error.ts b/projects/backend/src/error/internal-server-error.ts new file mode 100644 index 0000000..5172c4a --- /dev/null +++ b/projects/backend/src/error/internal-server-error.ts @@ -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); + } +} diff --git a/projects/backend/src/model/player.ts b/projects/backend/src/model/player.ts index d4e6564..e3f944e 100644 --- a/projects/backend/src/model/player.ts +++ b/projects/backend/src/model/player.ts @@ -20,9 +20,18 @@ export class Player { @prop() private statisticHistory?: Record; + /** + * 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. */ diff --git a/projects/backend/src/service/player.service.ts b/projects/backend/src/service/player.service.ts index fdcdbc8..6e3e22f 100644 --- a/projects/backend/src/service/player.service.ts +++ b/projects/backend/src/service/player.service.ts @@ -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 {