diff --git a/app/api/src/app.module.ts b/app/api/src/app.module.ts index 655fe17..5a61b6c 100644 --- a/app/api/src/app.module.ts +++ b/app/api/src/app.module.ts @@ -7,6 +7,7 @@ import { ConfigModule } from '@nestjs/config'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { GamesModule } from './games/games.module'; +import { GameModule } from './game/game.module'; @Module({ imports: [ @@ -25,7 +26,8 @@ import { GamesModule } from './games/games.module'; database: process.env.DATABASE_NAME, autoLoadEntities: true // models will be loaded automatically (you don't have to explicitly specify the entities: [] array) }), - GamesModule + GamesModule, + GameModule ], controllers: [ AppController ], providers: [ AppService ] diff --git a/app/api/src/entities/Players.ts b/app/api/src/entities/Players.ts index 7692d41..cbf31dd 100644 --- a/app/api/src/entities/Players.ts +++ b/app/api/src/entities/Players.ts @@ -1,5 +1,5 @@ import { Column, Entity, Index, OneToMany, PrimaryGeneratedColumn } from 'typeorm'; -import { GameDetail } from '../games/entities/GameDetail'; +import { GameDetail } from '../game/entities/GameDetail'; @Index('players_pk', [ 'playerGuid' ], { unique: true }) @Index('players_player_name_key', [ 'playerName' ], { unique: true }) @@ -57,6 +57,6 @@ export class Players { }) updatedAt: Date; - @OneToMany(() => GameDetail, (gameDetail) => gameDetail.playerGuid) - gameDetails: GameDetail[]; + // @OneToMany(() => GameDetail, (gameDetail) => gameDetail.playerGuid) + // gameDetails: GameDetail[]; } diff --git a/app/api/src/games/entities/GameDetail.ts b/app/api/src/game/entities/GameDetail.ts similarity index 72% rename from app/api/src/games/entities/GameDetail.ts rename to app/api/src/game/entities/GameDetail.ts index 63a4256..80be141 100644 --- a/app/api/src/games/entities/GameDetail.ts +++ b/app/api/src/game/entities/GameDetail.ts @@ -1,5 +1,5 @@ import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm'; -import { Games } from './Games'; +import { Games } from '../../games/entities/Games'; import { Players } from '../../entities/Players'; @Index('games_pk', [ 'id' ], { unique: true }) @@ -36,11 +36,11 @@ export class GameDetail { }) createdAt: Date; - // @ManyToOne(() => Games, (games) => games.gameDetails) - // @JoinColumn([ { name: 'game_id', referencedColumnName: 'gameId' } ]) - // game: Games; + @ManyToOne(() => Games, (games) => games.gameDetails) + @JoinColumn([ { name: 'game_id', referencedColumnName: 'gameId' } ]) + game: Games; - @ManyToOne(() => Players, (players) => players.gameDetails) - @JoinColumn([ { name: 'player_guid', referencedColumnName: 'playerGuid' } ]) - playerGuid: Players; + // @ManyToOne(() => Players, (players) => players.gameDetails) + // @JoinColumn([ { name: 'player_guid', referencedColumnName: 'playerGuid' } ]) + // playerGuid: Players; } diff --git a/app/api/src/game/game.controller.spec.ts b/app/api/src/game/game.controller.spec.ts new file mode 100644 index 0000000..23d9a2f --- /dev/null +++ b/app/api/src/game/game.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { GameController } from './game.controller'; + +describe('Game Controller', () => { + let controller: GameController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [GameController], + }).compile(); + + controller = module.get(GameController); + }); + + it('should be defined', () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/app/api/src/game/game.controller.ts b/app/api/src/game/game.controller.ts new file mode 100644 index 0000000..3ec34f0 --- /dev/null +++ b/app/api/src/game/game.controller.ts @@ -0,0 +1,13 @@ +import { Controller, Get, Param, Query } from '@nestjs/common'; +import { GameService } from './game.service'; + +@Controller('game') +export class GameController { + constructor(private readonly gameService: GameService) {} + + // /games/:gameId + @Get(':gameId') + findOne(@Param('gameId') gameId: string) { + return this.gameService.findOne(gameId); + } +} diff --git a/app/api/src/game/game.module.ts b/app/api/src/game/game.module.ts new file mode 100644 index 0000000..a3948dd --- /dev/null +++ b/app/api/src/game/game.module.ts @@ -0,0 +1,16 @@ +import { Module } from '@nestjs/common'; +import { ConfigModule } from '@nestjs/config'; +import { TypeOrmModule } from '@nestjs/typeorm'; + +import { GameController } from './game.controller'; +import { GameService } from './game.service'; + +import { GameDetail } from './entities/GameDetail'; +import { Games } from '../games/entities/Games'; + +@Module({ + imports: [ TypeOrmModule.forFeature([ Games, GameDetail ]), ConfigModule ], + controllers: [ GameController ], + providers: [ GameService ] +}) +export class GameModule {} diff --git a/app/api/src/game/game.service.spec.ts b/app/api/src/game/game.service.spec.ts new file mode 100644 index 0000000..f4a1db7 --- /dev/null +++ b/app/api/src/game/game.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from '@nestjs/testing'; +import { GameService } from './game.service'; + +describe('GameService', () => { + let service: GameService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [GameService], + }).compile(); + + service = module.get(GameService); + }); + + it('should be defined', () => { + expect(service).toBeDefined(); + }); +}); diff --git a/app/api/src/game/game.service.ts b/app/api/src/game/game.service.ts new file mode 100644 index 0000000..9b7b6ff --- /dev/null +++ b/app/api/src/game/game.service.ts @@ -0,0 +1,23 @@ +import { Injectable, NotFoundException } from '@nestjs/common'; +import { ConfigService } from '@nestjs/config'; +import { InjectRepository } from '@nestjs/typeorm'; +import { Connection, Repository } from 'typeorm'; + +import { GameDetail } from './entities/GameDetail'; + +@Injectable() +export class GameService { + constructor( + private readonly connection: Connection, + private readonly configService: ConfigService, + @InjectRepository(GameDetail) private readonly gameRepository: Repository + ) {} + + async findOne(gameId: string) { + const game = await this.gameRepository.find({ where: { gameId: gameId } }); + if (!game) { + throw new NotFoundException(`Game ID: ${gameId} not found`); + } + return game; + } +} diff --git a/app/api/src/games/entities/Games.ts b/app/api/src/games/entities/Games.ts index 2a5d629..9722f31 100644 --- a/app/api/src/games/entities/Games.ts +++ b/app/api/src/games/entities/Games.ts @@ -1,5 +1,5 @@ import { Column, Entity, Index, OneToMany } from 'typeorm'; -import { GameDetail } from './GameDetail'; +import { GameDetail } from '../../game/entities/GameDetail'; @Index('game_pk', [ 'gameId' ], { unique: true }) @Entity('games', { schema: 'public' }) @@ -21,4 +21,11 @@ export class Games { default: () => 'now()' }) createdAt: Date; + + @OneToMany(() => GameDetail, (gameDetail) => Games.gameDetail) + gameDetails: GameDetail[]; + + @ManyToOne(() => Games, (games) => games.gameDetail) + @JoinColumn([ { name: 'game_id', referencedColumnName: 'gameId' } ]) + game: Games; } diff --git a/app/api/src/games/games.controller.ts b/app/api/src/games/games.controller.ts index 5ffa0ee..651ced8 100644 --- a/app/api/src/games/games.controller.ts +++ b/app/api/src/games/games.controller.ts @@ -20,7 +20,7 @@ export class GamesController { return this.gameService.findByType(gametype); } - // /game/:gameId + // /games/:gameId @Get(':gameId') findOne(@Param('gameId') gameId: string) { return this.gameService.findOne(gameId); diff --git a/app/api/src/games/games.module.ts b/app/api/src/games/games.module.ts index e7e89de..bca13a2 100644 --- a/app/api/src/games/games.module.ts +++ b/app/api/src/games/games.module.ts @@ -6,9 +6,10 @@ import { GamesController } from './games.controller'; import { GamesService } from './games.service'; import { Games } from './entities/Games'; +import { GameDetail } from '../game/entities/GameDetail'; @Module({ - imports: [ TypeOrmModule.forFeature([ Games ]), ConfigModule ], + imports: [ TypeOrmModule.forFeature([ Games, GameDetail ]), ConfigModule ], controllers: [ GamesController ], providers: [ GamesService ] }) diff --git a/app/api/src/games/games.service.ts b/app/api/src/games/games.service.ts index 4d62b3e..0fc6cc6 100644 --- a/app/api/src/games/games.service.ts +++ b/app/api/src/games/games.service.ts @@ -1,9 +1,9 @@ import { Injectable, NotFoundException } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; +import { InjectRepository } from '@nestjs/typeorm'; import { Connection, Repository } from 'typeorm'; import { Games } from './entities/Games'; -import { InjectRepository } from '@nestjs/typeorm'; import { PaginationQueryDto } from '../common/dto/pagination-query.dto'; @Injectable()