cleanup getting the player
All checks were successful
Deploy Backend / deploy (push) Successful in 2m12s

This commit is contained in:
Lee 2024-10-11 01:12:27 +01:00
parent 26e34c32f1
commit f649fb9c7f

View File

@ -16,17 +16,15 @@ export class PlayerService {
*/
public static async getPlayer(id: string, create: boolean = false): Promise<PlayerDocument> {
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}"`);
}