Setup game module

This commit is contained in:
Anthony Mineo 2020-08-23 11:04:35 -04:00
parent 2d90f9dde8
commit 2abedc99f9
12 changed files with 113 additions and 15 deletions

View file

@ -0,0 +1,46 @@
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
import { Games } from '../../games/entities/Games';
import { Players } from '../../entities/Players';
@Index('games_pk', [ 'id' ], { unique: true })
@Index('game_detail_uuid_key', [ 'uuid' ], { unique: true })
@Entity('game_detail', { schema: 'public' })
export class GameDetail {
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
id: number;
@Column('text', { name: 'player_name' })
playerName: string;
@Column('numeric', { name: 'stat_overwrite' })
statOverwrite: string;
@Column('text', { name: 'map' })
map: string;
@Column('jsonb', { name: 'stats' })
stats: any;
@Column('timestamp without time zone', { name: 'datestamp' })
datestamp: Date;
@Column('text', { name: 'uuid', unique: true })
uuid: string;
@Column('text', { name: 'gametype' })
gametype: string;
@Column('timestamp with time zone', {
name: 'created_at',
default: () => 'now()'
})
createdAt: Date;
@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;
}

View 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();
});
});

View 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);
}
}

View 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 {}

View 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();
});
});

View 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;
}
}