Skip to content

Commit

Permalink
return eventId and competitionId
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed Mar 24, 2024
1 parent 6ea645a commit 2d1bbaa
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/athletes/athlete.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions src/athletes/athlete.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const ATHLETE_QUERY = gql`
resultScore
wind
records
eventId
competitionId
}
activeSeasons
}
Expand All @@ -35,6 +37,8 @@ const ATHLETE_QUERY = gql`
resultScore
wind
records
eventId
competitionId
}
}
worldRankings {
Expand All @@ -56,6 +60,8 @@ const ATHLETE_QUERY = gql`
venue
mark
date
eventId
competitionId
}
categoryName
}
Expand Down
44 changes: 44 additions & 0 deletions src/athletes/athlete.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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({
Expand Down
5 changes: 5 additions & 0 deletions src/athletes/athletes.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/athletes/athletes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -123,6 +125,8 @@ export class AthletesService {
race: null,
place: null,
records: result.records,
competitionId: result.competitionId,
eventId: result.eventId,
};
},
),
Expand All @@ -143,7 +147,8 @@ export class AthletesService {
indoor,
competition: result.competition,
place: result.place,
resultScore: 0,
competitionId: result.competitionId,
eventId: result.eventId,
};
}),
};
Expand Down
2 changes: 2 additions & 0 deletions src/athletes/results/result.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const RESULTS_QUERY = gql`
race
place
category
eventId
competitionId
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/athletes/results/result.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export class ResultsService {
location: parseVenue(result.venue),
race: result.race,
records: null,
competitionId: result.competitionId,
eventId: result.eventId,
});
});
},
Expand Down
22 changes: 22 additions & 0 deletions src/athletes/results/result.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
}),
),
}),
Expand Down

0 comments on commit 2d1bbaa

Please sign in to comment.