From f649fb9c7ff181a85a0371baa0978732ac45db60 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 11 Oct 2024 01:12:27 +0100 Subject: [PATCH] cleanup getting the player --- projects/backend/src/service/player.service.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/projects/backend/src/service/player.service.ts b/projects/backend/src/service/player.service.ts index fccd847..acda106 100644 --- a/projects/backend/src/service/player.service.ts +++ b/projects/backend/src/service/player.service.ts @@ -16,17 +16,15 @@ export class PlayerService { */ public static async getPlayer(id: string, create: boolean = false): Promise { let player: PlayerDocument | null = await PlayerModel.findById(id); - if (player === null && !create) { - throw new NotFoundError(`Player "${id}" not found`); - } if (player === null) { - const playerToken = await scoresaberService.lookupPlayer(id); + // If create is on, create the player, otherwise return unknown player + const playerToken = create ? await scoresaberService.lookupPlayer(id) : undefined; if (playerToken === undefined) { throw new NotFoundError(`Player "${id}" not found`); } console.log(`Creating player "${id}"...`); - player = (await PlayerModel.create({ _id: id })) as any; + player = (await PlayerModel.create({ _id: id })) as PlayerDocument; if (player === null) { throw new InternalServerError(`Failed to create player document for "${id}"`); }