diff --git a/src/app.module.ts b/src/app.module.ts index 0b85fe3..892163a 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -1,4 +1,4 @@ -import { Module } from '@nestjs/common'; +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'; @@ -8,6 +8,8 @@ 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'; +import { CompetitionsModule } from './competitions/competitions.module'; +import { LoggerMiddleware } from './logger.middleware'; @Module({ imports: [ @@ -20,6 +22,7 @@ import { GraphqlModule } from './graphql/graphql.module'; DisciplinesModule, AthleteRepresentativesModule, GraphqlModule, + CompetitionsModule, ], providers: [ { @@ -28,4 +31,8 @@ import { GraphqlModule } from './graphql/graphql.module'; }, ], }) -export class AppModule {} +export class AppModule { + configure(consumer: MiddlewareConsumer): void { + consumer.apply(LoggerMiddleware).forRoutes('*'); + } +} diff --git a/src/competitions/competition.dto.ts b/src/competitions/competition.dto.ts new file mode 100644 index 0000000..bf9bf44 --- /dev/null +++ b/src/competitions/competition.dto.ts @@ -0,0 +1,25 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class CompetitionOrganiserInfo { + @ApiProperty() + websiteUrl: string; + @ApiProperty() + liveStreamUrl: string; + @ApiProperty() + resultsUrl: string; + @ApiProperty() + events: any[]; + @ApiProperty() + contactPersons: ContactPerson[]; +} + +export class ContactPerson { + @ApiProperty() + email: string; + @ApiProperty() + name: string; + @ApiProperty() + phone: string; + @ApiProperty() + role: string; +} diff --git a/src/competitions/competitions.controller.ts b/src/competitions/competitions.controller.ts new file mode 100644 index 0000000..f50e77a --- /dev/null +++ b/src/competitions/competitions.controller.ts @@ -0,0 +1,24 @@ +import { Controller, Get, Param } from '@nestjs/common'; +import { CompetitionsService } from './competitions.service'; + +@Controller('competitions') +export class CompetitionsController { + constructor(private readonly competitionsService: CompetitionsService) {} + + @Get() + findAll() { + return null; + } + + @Get(':id') + findOne(@Param('id') id: string) { + console.log(id); + return null; + } + + @Get(':id/organiser') + findOrganiser(@Param('id') id: string) { + console.log(id); + return null; + } +} diff --git a/src/competitions/competitions.module.ts b/src/competitions/competitions.module.ts new file mode 100644 index 0000000..1b66b77 --- /dev/null +++ b/src/competitions/competitions.module.ts @@ -0,0 +1,10 @@ +import { Module } from '@nestjs/common'; +import { CompetitionsService } from './competitions.service'; +import { CompetitionsController } from './competitions.controller'; +import { GraphqlService } from 'src/graphql/graphql.service'; + +@Module({ + controllers: [CompetitionsController], + providers: [CompetitionsService, GraphqlService], +}) +export class CompetitionsModule {} diff --git a/src/competitions/competitions.service.ts b/src/competitions/competitions.service.ts new file mode 100644 index 0000000..320a49b --- /dev/null +++ b/src/competitions/competitions.service.ts @@ -0,0 +1,16 @@ +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class CompetitionsService { + findAll() { + return `This action returns all competitions`; + } + + findOne(id: number) { + return `This action returns a #${id} competition`; + } + + remove(id: number) { + return `This action removes a #${id} competition`; + } +} diff --git a/src/logger.middleware.ts b/src/logger.middleware.ts new file mode 100644 index 0000000..50286ec --- /dev/null +++ b/src/logger.middleware.ts @@ -0,0 +1,23 @@ +import { Injectable, Logger, NestMiddleware } from '@nestjs/common'; +import { Request, Response, NextFunction } from 'express'; + +@Injectable() +export class LoggerMiddleware implements NestMiddleware { + private logger = new Logger('HTTP'); + + use(request: Request, response: Response, next: NextFunction): void { + const { method, originalUrl } = request; + const userAgent = request.get('user-agent') || ''; + + response.on('finish', () => { + const { statusCode } = response; + const contentLength = response.get('content-length'); + + this.logger.log( + `${method} ${originalUrl} ${statusCode} ${contentLength} - ${userAgent}`, + ); + }); + + next(); + } +}