Finish API services

This commit is contained in:
Anthony Mineo 2020-08-29 11:11:21 -04:00
parent 2abedc99f9
commit 0db8a7f439
18 changed files with 243 additions and 23 deletions

View file

@ -1,6 +1,7 @@
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Games } from '../../games/entities/Games';
import { Players } from '../../entities/Players';
import { Players } from '../../players/entities/Players';
@Index('games_pk', [ 'id' ], { unique: true })
@Index('game_detail_uuid_key', [ 'uuid' ], { unique: true })
@ -12,7 +13,7 @@ export class GameDetail {
@Column('text', { name: 'player_name' })
playerName: string;
@Column('numeric', { name: 'stat_overwrite' })
@Column('numeric', { name: 'stat_overwrite', select: false })
statOverwrite: string;
@Column('text', { name: 'map' })
@ -40,7 +41,7 @@ export class GameDetail {
@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;
}

View file

@ -1,4 +1,4 @@
import { Controller, Get, Param, Query } from '@nestjs/common';
import { Controller, Get, Param } from '@nestjs/common';
import { GameService } from './game.service';
@Controller('game')

View file

@ -8,8 +8,10 @@ import { GameService } from './game.service';
import { GameDetail } from './entities/GameDetail';
import { Games } from '../games/entities/Games';
import { Players } from '../players/entities/Players';
@Module({
imports: [ TypeOrmModule.forFeature([ Games, GameDetail ]), ConfigModule ],
imports: [ TypeOrmModule.forFeature([ Games, GameDetail, Players ]), ConfigModule ],
controllers: [ GameController ],
providers: [ GameService ]
})

View file

@ -3,6 +3,7 @@ import { ConfigService } from '@nestjs/config';
import { InjectRepository } from '@nestjs/typeorm';
import { Connection, Repository } from 'typeorm';
import { Games } from '../games/entities/Games';
import { GameDetail } from './entities/GameDetail';
@Injectable()
@ -10,11 +11,15 @@ export class GameService {
constructor(
private readonly connection: Connection,
private readonly configService: ConfigService,
@InjectRepository(Games) private readonly gamesRepository: Repository<Games>,
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
) {}
async findOne(gameId: string) {
const game = await this.gameRepository.find({ where: { gameId: gameId } });
const game = await this.gameRepository.find({
relations: [ 'game', 'playerGuid' ],
where: [ { game: { gameId: gameId } } ]
});
if (!game) {
throw new NotFoundException(`Game ID: ${gameId} not found`);
}