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}"`); }