mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-03-04 12:20:21 +00:00
Setup game module
This commit is contained in:
parent
2d90f9dde8
commit
2abedc99f9
12 changed files with 113 additions and 15 deletions
46
app/api/src/game/entities/GameDetail.ts
Normal file
46
app/api/src/game/entities/GameDetail.ts
Normal 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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue