Skip to content

Commit

Permalink
get ar id
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed May 27, 2024
1 parent f116ddb commit 87cc959
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 8 deletions.
25 changes: 24 additions & 1 deletion src/athlete_representatives/athlete_representatives.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ export class AthleteRepresentativesService {
this.graphQLClient = new GraphQLClient(process.env.STELLATE_ENDPOINT);
}

sanitizeEmail(email) {
// Define regex for valid characters in the local part of the email
const localPartRegex = /[^a-zA-Z0-9._%+-]/g;
// Define regex for valid characters in the domain part of the email
const domainPartRegex = /[^a-zA-Z0-9.-]/g;

// Split the email into local and domain parts
let [localPart, domainPart] = email.split('@');

// Sanitize the local part
localPart = localPart.replace(localPartRegex, '');

// Sanitize the domain part if it exists
if (domainPart) {
domainPart = domainPart.replace(domainPartRegex, '');
}

// Reassemble the sanitized email
return domainPart ? `${localPart}@${domainPart}` : localPart;
}

async getAthleteRepresentative(
id: number,
): Promise<AthleteRepresentative | null> {
Expand All @@ -40,7 +61,9 @@ export class AthleteRepresentativesService {
country: response.getAthleteRepresentativeProfile.countryCode,
email:
response.getAthleteRepresentativeProfile.email.length > 0
? response.getAthleteRepresentativeProfile.email[0]
? this.sanitizeEmail(
response.getAthleteRepresentativeProfile.email[0],
)
: null,
firstname: response.getAthleteRepresentativeProfile.firstName,
lastname: formatLastname(
Expand Down
2 changes: 2 additions & 0 deletions src/athletes/athlete.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,6 @@ export class Athlete {
honours: Honour[];
@ApiProperty({ type: Number, isArray: true })
activeSeasons: number[];
@ApiProperty({ nullable: true, type: Number })
athleteRepresentativeId: number | null;
}
8 changes: 1 addition & 7 deletions src/athletes/athlete.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ const ATHLETE_QUERY = gql`
sexNameUrlSlug
}
athleteRepresentative {
name
email
mobile
telephone
email
countryCode
countryName
_id
}
seasonsBests {
results {
Expand Down
1 change: 1 addition & 0 deletions src/athletes/athlete.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,5 @@ export const Athlete = z.object({
categoryName: z.string(),
}),
),
athleteRepresentative: z.nullable(z.object({ _id: z.number() })),
});
2 changes: 2 additions & 0 deletions src/athletes/athletes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export class AthletesService {
? 'FEMALE'
: 'MALE'
: worldRankingSex,
athleteRepresentativeId:
response.getSingleCompetitor.athleteRepresentative?._id ?? null,
activeSeasons: response.getSingleCompetitor.seasonsBests.activeSeasons,
currentWorldRankings:
response.getSingleCompetitor.worldRankings.current.map((ranking) => {
Expand Down

0 comments on commit 87cc959

Please sign in to comment.