mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
Setup game module
This commit is contained in:
parent
2d90f9dde8
commit
2abedc99f9
|
|
@ -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 ]
|
||||
|
|
|
|||
|
|
@ -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[];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
18
app/api/src/game/game.controller.spec.ts
Normal file
18
app/api/src/game/game.controller.spec.ts
Normal file
|
|
@ -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>(GameController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
13
app/api/src/game/game.controller.ts
Normal file
13
app/api/src/game/game.controller.ts
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
16
app/api/src/game/game.module.ts
Normal file
16
app/api/src/game/game.module.ts
Normal file
|
|
@ -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 {}
|
||||
18
app/api/src/game/game.service.spec.ts
Normal file
18
app/api/src/game/game.service.spec.ts
Normal file
|
|
@ -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>(GameService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
23
app/api/src/game/game.service.ts
Normal file
23
app/api/src/game/game.service.ts
Normal file
|
|
@ -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<GameDetail>
|
||||
) {}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 ]
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue