diff --git a/src/athletes/athlete.dto.ts b/src/athletes/athlete.dto.ts index 784e892..b60b21a 100644 --- a/src/athletes/athlete.dto.ts +++ b/src/athletes/athlete.dto.ts @@ -26,14 +26,18 @@ export class Performance { wind: number | null; @ApiProperty({ nullable: true, type: String }) competition: string | null; + @ApiProperty({ nullable: true, type: Number }) + competitionId: number | null; + @ApiProperty({ nullable: true, type: Number }) + eventId: number | null; @ApiProperty({ nullable: true, type: String }) category: string | null; @ApiProperty({ nullable: true, type: String }) race: string | null; @ApiProperty({ nullable: true, type: Number }) place: number | null; - @ApiProperty({ nullable: true, type: String, isArray: true }) - records: string[] | null; + @ApiProperty({ type: String, isArray: true }) + records: string[]; } export class CurrentWorldRanking { @@ -64,6 +68,10 @@ export class HonourResult { date: Date; @ApiProperty() competition: string; + @ApiProperty({ nullable: true, type: Number }) + competitionId: number | null; + @ApiProperty({ nullable: true, type: Number }) + eventId: number | null; } export class Honour { diff --git a/src/athletes/athlete.query.ts b/src/athletes/athlete.query.ts index f82c6d9..15fc024 100644 --- a/src/athletes/athlete.query.ts +++ b/src/athletes/athlete.query.ts @@ -21,6 +21,8 @@ const ATHLETE_QUERY = gql` resultScore wind records + eventId + competitionId } activeSeasons } @@ -35,6 +37,8 @@ const ATHLETE_QUERY = gql` resultScore wind records + eventId + competitionId } } worldRankings { @@ -56,6 +60,8 @@ const ATHLETE_QUERY = gql` venue mark date + eventId + competitionId } categoryName } diff --git a/src/athletes/athlete.zod.ts b/src/athletes/athlete.zod.ts index f701e2b..beeefa3 100644 --- a/src/athletes/athlete.zod.ts +++ b/src/athletes/athlete.zod.ts @@ -41,6 +41,28 @@ const Performance = z.object({ }, z.number().nullable()) .nullable(), records: z.array(z.string()), + eventId: z.preprocess((val) => { + if (val === null) { + return null; + } + try { + return Number(val); + } catch (error) { + console.log(val, error); + return null; + } + }, z.number().nullable()), + competitionId: z.preprocess((val) => { + if (val === null) { + return null; + } + try { + return Number(val); + } catch (error) { + console.log(val, error); + return null; + } + }, z.number().nullable()), }); const WorldRanking = z.object({ @@ -63,6 +85,28 @@ const Result = z.object({ place: z.preprocess((val) => { return Number(val); }, z.number()), + competitionId: z.preprocess((val) => { + if (val == null) { + return null; + } + try { + return Number(val); + } catch (error) { + console.log(val, error); + return null; + } + }, z.number().nullable()), + eventId: z.preprocess((val) => { + if (val == null) { + return null; + } + try { + return Number(val); + } catch (error) { + console.log(val, error); + return null; + } + }, z.number().nullable()), }); export const Athlete = z.object({ diff --git a/src/athletes/athletes.controller.ts b/src/athletes/athletes.controller.ts index 4eed35a..0345702 100644 --- a/src/athletes/athletes.controller.ts +++ b/src/athletes/athletes.controller.ts @@ -43,6 +43,11 @@ export class AthletesController { type: Number, required: false, }) + @ApiOkResponse({ + description: 'Returns the athlete results', + type: Performance, + isArray: true, + }) async getResultsbyAthleteId( @Param('id', ParseIntPipe) id: number, @Query('year') year?: number, diff --git a/src/athletes/athletes.service.ts b/src/athletes/athletes.service.ts index dde627b..f688751 100644 --- a/src/athletes/athletes.service.ts +++ b/src/athletes/athletes.service.ts @@ -99,6 +99,8 @@ export class AthletesService { race: null, place: null, records: result.records, + competitionId: result.competitionId, + eventId: result.eventId, }; }), personalbests: response.getSingleCompetitor.personalBests.results.map( @@ -123,6 +125,8 @@ export class AthletesService { race: null, place: null, records: result.records, + competitionId: result.competitionId, + eventId: result.eventId, }; }, ), @@ -143,7 +147,8 @@ export class AthletesService { indoor, competition: result.competition, place: result.place, - resultScore: 0, + competitionId: result.competitionId, + eventId: result.eventId, }; }), }; diff --git a/src/athletes/results/result.query.ts b/src/athletes/results/result.query.ts index a28df9a..fcb79b8 100644 --- a/src/athletes/results/result.query.ts +++ b/src/athletes/results/result.query.ts @@ -22,6 +22,8 @@ const RESULTS_QUERY = gql` race place category + eventId + competitionId } } } diff --git a/src/athletes/results/result.service.ts b/src/athletes/results/result.service.ts index 6a5b31d..85f8bb6 100644 --- a/src/athletes/results/result.service.ts +++ b/src/athletes/results/result.service.ts @@ -63,6 +63,8 @@ export class ResultsService { location: parseVenue(result.venue), race: result.race, records: null, + competitionId: result.competitionId, + eventId: result.eventId, }); }); }, diff --git a/src/athletes/results/result.zod.ts b/src/athletes/results/result.zod.ts index d274d1f..b99a3df 100644 --- a/src/athletes/results/result.zod.ts +++ b/src/athletes/results/result.zod.ts @@ -48,6 +48,28 @@ export const ResultsByEvent = z.object({ } }, z.number()), category: z.string().nullable().default('F'), + competitionId: z.preprocess((val) => { + if (val == null) { + return null; + } + try { + return Number(val); + } catch (error) { + console.log(val, error); + return null; + } + }, z.number().nullable()), + eventId: z.preprocess((val) => { + if (val == null) { + return null; + } + try { + return Number(val); + } catch (error) { + console.log(val, error); + return null; + } + }, z.number().nullable()), }), ), }),