diff --git a/src/athletes/athletes.controller.ts b/src/athletes/athletes.controller.ts index 75f898e..1658b34 100644 --- a/src/athletes/athletes.controller.ts +++ b/src/athletes/athletes.controller.ts @@ -47,9 +47,31 @@ export class AthletesController { @Param('id', ParseIntPipe) id: number, @Query('year') year?: number, ): Promise { + if (!year) { + const athlete = await this.athletesService.getAthlete(id); + if (!athlete) { + throw new NotFoundException(); + } + const allResults = []; + const promises = athlete.activeSeasons.map(async (season) => { + try { + const results = await this.resultsService.getResultsFromAthlete( + id, + season, + ); + if (results) { + allResults.push(results); + } + } catch (error) { + console.error(`Error fetching results for season ${season}:`, error); + } + }); + await Promise.all(promises); + return allResults; + } const results = await this.resultsService.getResultsFromAthlete(id, year); if (!results) { - throw new NotFoundException(); + return []; } return results; } diff --git a/src/athletes/results/result.service.ts b/src/athletes/results/result.service.ts index 22c59ca..6a5b31d 100644 --- a/src/athletes/results/result.service.ts +++ b/src/athletes/results/result.service.ts @@ -67,7 +67,7 @@ export class ResultsService { }); }, ); - return results; + return results.filter((result) => result.place > 0); } catch (error) { console.log(error); } diff --git a/src/athletes/results/result.zod.ts b/src/athletes/results/result.zod.ts index 9ce3cf6..d274d1f 100644 --- a/src/athletes/results/result.zod.ts +++ b/src/athletes/results/result.zod.ts @@ -37,13 +37,17 @@ export const ResultsByEvent = z.object({ return 0; } try { - return Number(val); + const number = Number(val); + if (isNaN(number)) { + return -1; + } + return number; } catch (error) { console.log(val, error); return -1; } }, z.number()), - category: z.string(), + category: z.string().nullable().default('F'), }), ), }),