Skip to content

Commit

Permalink
remove serntry,termius, refactor type classes
Browse files Browse the repository at this point in the history
  • Loading branch information
nimarion committed Aug 6, 2024
1 parent f9871bd commit d51dab3
Show file tree
Hide file tree
Showing 18 changed files with 1,708 additions and 6,620 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The project provides a standardized method for fetching athlete and competition
- Country (Country Code, Country Name, Area Code, Area Name)
- Competition results
- Competition details
- All Worldrecords,Arearecords,Worldleads,Arealeads,Olympicrecords,Championshiprecords,...
- All ratified Worldrecords,Arearecords,Worldleads,Arealeads,Olympicrecords,Championshiprecords,...

For field events the service converts the results to centimeters and milliseconds for track events. Athletes seasonbests results older than 12 months are filtered out. The search endpoint /athletes/search?name adds a field with the calculated levenshtein distance between the search query and the results. Results are sorted by the levenshtein distance.

Expand Down
8,062 changes: 1,660 additions & 6,402 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"author": "",
"private": true,
"license": "UNLICENSED",
"license": "MIT",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
Expand All @@ -22,9 +22,6 @@
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^10.2.10",
"@nestjs/swagger": "^7.1.16",
"@nestjs/terminus": "^10.1.1",
"@sentry/node": "^7.81.0",
"@sentry/tracing": "^7.81.0",
"graphql-request": "^6.1.0",
"libphonenumber-js": "^1.11.2",
"reflect-metadata": "^0.1.13",
Expand Down
10 changes: 0 additions & 10 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { MiddlewareConsumer, Module } from '@nestjs/common';
import { AthletesModule } from './athletes/athletes.module';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { SentryInterceptor } from './sentry-interceptor/sentry-interceptor.interceptor';
import { CountriesModule } from './countries/countries.module';
import { ConfigModule } from '@nestjs/config';
import { HealthModule } from './health/health.module';
import { DisciplinesModule } from './disciplines/disciplines.module';
import { AthleteRepresentativesModule } from './athlete_representatives/athlete_representatives.module';
import { GraphqlModule } from './graphql/graphql.module';
Expand All @@ -15,7 +12,6 @@ import { RecordsModule } from './records/records.module';
@Module({
imports: [
AthletesModule,
HealthModule,
CountriesModule,
ConfigModule.forRoot({
isGlobal: true,
Expand All @@ -26,12 +22,6 @@ import { RecordsModule } from './records/records.module';
CompetitionsModule,
RecordsModule,
],
providers: [
{
provide: APP_INTERCEPTOR,
useClass: SentryInterceptor,
},
],
})
export class AppModule {
configure(consumer: MiddlewareConsumer): void {
Expand Down
87 changes: 28 additions & 59 deletions src/athletes/athlete.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import { ApiProperty } from '@nestjs/swagger';
import { ApiProperty, OmitType } from '@nestjs/swagger';
import { Location } from './location.dto';
import { Discipline } from 'src/disciplines/discipline.entity';

export class Performance {
export class BaseAthlete {
@ApiProperty()
date: Date;
id: number;
@ApiProperty()
firstname: string;
@ApiProperty()
discipline: string;
lastname: string;
@ApiProperty({ nullable: true, type: Date })
birthdate: Date | null;
@ApiProperty()
disciplineCode: string;
country: string;
@ApiProperty({
description: 'null if sex could not be determined',
nullable: true,
enum: ['MALE', 'FEMALE'],
})
sex: 'MALE' | 'FEMALE' | null;
}

export class BasePerformance extends Discipline {
@ApiProperty()
shortTrack: boolean;
date: Date;
@ApiProperty()
mark: string;
@ApiProperty({
Expand All @@ -20,14 +34,15 @@ export class Performance {
performanceValue: number | null;
@ApiProperty()
location: Location;
@ApiProperty()
indoor: boolean;
@ApiProperty({ nullable: true, type: Number })
wind: number | null;
}

export class Performance extends BasePerformance {
@ApiProperty()
legal: boolean;
@ApiProperty()
resultScore: number;
@ApiProperty({ nullable: true, type: Number })
wind: number | null;
@ApiProperty({ nullable: true, type: String })
competition: string | null;
@ApiProperty({ nullable: true, type: Number })
Expand All @@ -51,32 +66,10 @@ export class CurrentWorldRanking {
eventGroup: string;
}

export class HonourResult {
export class HonourResult extends OmitType(BasePerformance, ['wind'] as const) {
@ApiProperty()
place: number;
@ApiProperty()
indoor: boolean;
@ApiProperty()
discipline: string;
@ApiProperty()
disciplineCode: string;
@ApiProperty()
shortTrack: boolean;
@ApiProperty()
mark: string;
@ApiProperty({
description:
'Performance in milliseconds for track events and centimeters for field events',
nullable: true,
})
performanceValue: number | null;
@ApiProperty()
venue: string;
@ApiProperty()
location: Location;
@ApiProperty()
date: Date;
@ApiProperty()
competition: string;
@ApiProperty({ nullable: true, type: Number })
competitionId: number | null;
Expand All @@ -91,19 +84,7 @@ export class Honour {
category: string;
}

export class Athlete {
@ApiProperty()
id: number;
@ApiProperty()
firstname: string;
@ApiProperty()
lastname: string;
@ApiProperty({ nullable: true, type: Date })
birthdate: Date | null;
@ApiProperty()
country: string;
@ApiProperty({ nullable: true, enum: ['MALE', 'FEMALE'] })
sex: 'MALE' | 'FEMALE' | null;
export class Athlete extends BaseAthlete {
@ApiProperty({ type: Performance, isArray: true })
personalbests: Performance[];
@ApiProperty({ type: Performance, isArray: true })
Expand All @@ -118,19 +99,7 @@ export class Athlete {
athleteRepresentativeId: number | null;
}

export class AthleteSearchResult {
@ApiProperty()
id: number;
@ApiProperty()
country: string;
@ApiProperty()
firstname: string;
@ApiProperty()
lastname: string;
@ApiProperty({ nullable: true, enum: ['MALE', 'FEMALE'] })
sex: 'MALE' | 'FEMALE' | null;
@ApiProperty({ nullable: true, type: Date })
birthdate: Date | null;
export class AthleteSearchResult extends BaseAthlete {
@ApiProperty({
type: Number,
description: 'Levenshtein distance between search query and athlete name',
Expand Down
10 changes: 0 additions & 10 deletions src/athletes/athletes.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import { GraphQLClient } from 'graphql-request';
import { z } from 'zod';
import * as Sentry from '@sentry/node';
import { Athlete, AthleteSearchResult } from './athlete.dto';
import ATHLETE_QUERY, { ATHLETE_SEARCH_QUERY } from './athlete.query';
import { Athlete as AthleteSchema, AthleteSearchSchema } from './athlete.zod';
Expand Down Expand Up @@ -53,7 +52,6 @@ export class AthletesService {
);
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
return null;
}
Expand Down Expand Up @@ -134,7 +132,6 @@ export class AthletesService {
}),
}),
location,
indoor: location.indoor,
legal: !result.notLegal,
resultScore: result.resultScore,
wind: result.wind,
Expand Down Expand Up @@ -165,7 +162,6 @@ export class AthletesService {
}),
}),
location,
indoor: location.indoor,
legal: !result.notLegal,
resultScore: result.resultScore,
wind: result.wind,
Expand Down Expand Up @@ -198,9 +194,7 @@ export class AthletesService {
performance: result.mark,
}),
}),
venue: result.venue,
location,
indoor: location.indoor,
competition: result.competition,
place: result.place,
competitionId: result.competitionId,
Expand All @@ -212,10 +206,6 @@ export class AthletesService {
};
} catch (error) {
console.error(error);
Sentry.withScope((scope) => {
scope.setExtra('id', id);
Sentry.captureException(error);
});
}
return null;
}
Expand Down
1 change: 0 additions & 1 deletion src/athletes/results/result.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export class ResultsService {
discipline,
disciplineCode,
shortTrack: isShortTrack(discipline),
indoor: location.indoor,
place: result.place,
resultScore: result.resultScore,
wind: result.wind,
Expand Down
2 changes: 0 additions & 2 deletions src/competitions/competitions.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import { GraphQLClient } from 'graphql-request';
import { GraphqlService } from 'src/graphql/graphql.service';
import * as Sentry from '@sentry/node';
import { COMPETITION_ORGANISER } from './competition.query';
import { z } from 'zod';
import { CompetitionOrganiserInfo } from './competition.dto';
Expand Down Expand Up @@ -57,7 +56,6 @@ export class CompetitionsService {
};
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
return null;
}
Expand Down
2 changes: 0 additions & 2 deletions src/countries/countries.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Injectable } from '@nestjs/common';
import { gql, GraphQLClient } from 'graphql-request';
import { z } from 'zod';
import * as Sentry from '@sentry/node';
import { Country } from './country.entity';
import { GraphqlService } from 'src/graphql/graphql.service';

Expand Down Expand Up @@ -52,7 +51,6 @@ export class CountriesService {
});
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
return null;
}
Expand Down
3 changes: 1 addition & 2 deletions src/disciplines/disciplines.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { gql, GraphQLClient } from 'graphql-request';
import { z } from 'zod';
import { Discipline } from './discipline.entity';
import * as Sentry from '@sentry/node';

import { GraphqlService } from 'src/graphql/graphql.service';
import { isShortTrack } from 'src/utils';

Expand Down Expand Up @@ -48,7 +48,6 @@ export class DisciplinesService {
});
} catch (error) {
console.error(error);
Sentry.captureException(error);
}
return null;
}
Expand Down
20 changes: 0 additions & 20 deletions src/health/health.controller.ts

This file was deleted.

13 changes: 0 additions & 13 deletions src/health/health.module.ts

This file was deleted.

25 changes: 0 additions & 25 deletions src/health/worldathletics.health.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import * as Sentry from '@sentry/node';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors();
Sentry.init();
const config = new DocumentBuilder()
.setTitle('WorldAthletics Proxy API')
.setDescription('The worldathletics proxy API description')
Expand Down
Loading

0 comments on commit d51dab3

Please sign in to comment.