mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-07-11 22:34:34 +00:00
Finish API services
This commit is contained in:
parent
2abedc99f9
commit
0db8a7f439
18 changed files with 243 additions and 23 deletions
|
|
@ -8,6 +8,8 @@ import { AppController } from './app.controller';
|
||||||
import { AppService } from './app.service';
|
import { AppService } from './app.service';
|
||||||
import { GamesModule } from './games/games.module';
|
import { GamesModule } from './games/games.module';
|
||||||
import { GameModule } from './game/game.module';
|
import { GameModule } from './game/game.module';
|
||||||
|
import { PlayersModule } from './players/players.module';
|
||||||
|
import { PlayerModule } from './player/player.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
|
@ -27,7 +29,9 @@ import { GameModule } from './game/game.module';
|
||||||
autoLoadEntities: true // models will be loaded automatically (you don't have to explicitly specify the entities: [] array)
|
autoLoadEntities: true // models will be loaded automatically (you don't have to explicitly specify the entities: [] array)
|
||||||
}),
|
}),
|
||||||
GamesModule,
|
GamesModule,
|
||||||
GameModule
|
GameModule,
|
||||||
|
PlayersModule,
|
||||||
|
PlayerModule
|
||||||
],
|
],
|
||||||
controllers: [ AppController ],
|
controllers: [ AppController ],
|
||||||
providers: [ AppService ]
|
providers: [ AppService ]
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
|
|
||||||
import { Games } from '../../games/entities/Games';
|
import { Games } from '../../games/entities/Games';
|
||||||
import { Players } from '../../entities/Players';
|
import { Players } from '../../players/entities/Players';
|
||||||
|
|
||||||
@Index('games_pk', [ 'id' ], { unique: true })
|
@Index('games_pk', [ 'id' ], { unique: true })
|
||||||
@Index('game_detail_uuid_key', [ 'uuid' ], { unique: true })
|
@Index('game_detail_uuid_key', [ 'uuid' ], { unique: true })
|
||||||
|
|
@ -12,7 +13,7 @@ export class GameDetail {
|
||||||
@Column('text', { name: 'player_name' })
|
@Column('text', { name: 'player_name' })
|
||||||
playerName: string;
|
playerName: string;
|
||||||
|
|
||||||
@Column('numeric', { name: 'stat_overwrite' })
|
@Column('numeric', { name: 'stat_overwrite', select: false })
|
||||||
statOverwrite: string;
|
statOverwrite: string;
|
||||||
|
|
||||||
@Column('text', { name: 'map' })
|
@Column('text', { name: 'map' })
|
||||||
|
|
@ -40,7 +41,7 @@ export class GameDetail {
|
||||||
@JoinColumn([ { name: 'game_id', referencedColumnName: 'gameId' } ])
|
@JoinColumn([ { name: 'game_id', referencedColumnName: 'gameId' } ])
|
||||||
game: Games;
|
game: Games;
|
||||||
|
|
||||||
// @ManyToOne(() => Players, (players) => players.gameDetails)
|
@ManyToOne(() => Players, (players) => players.gameDetails)
|
||||||
// @JoinColumn([ { name: 'player_guid', referencedColumnName: 'playerGuid' } ])
|
@JoinColumn([ { name: 'player_guid', referencedColumnName: 'playerGuid' } ])
|
||||||
// playerGuid: Players;
|
playerGuid: Players;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
import { Controller, Get, Param } from '@nestjs/common';
|
||||||
import { GameService } from './game.service';
|
import { GameService } from './game.service';
|
||||||
|
|
||||||
@Controller('game')
|
@Controller('game')
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,10 @@ import { GameService } from './game.service';
|
||||||
import { GameDetail } from './entities/GameDetail';
|
import { GameDetail } from './entities/GameDetail';
|
||||||
import { Games } from '../games/entities/Games';
|
import { Games } from '../games/entities/Games';
|
||||||
|
|
||||||
|
import { Players } from '../players/entities/Players';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ TypeOrmModule.forFeature([ Games, GameDetail ]), ConfigModule ],
|
imports: [ TypeOrmModule.forFeature([ Games, GameDetail, Players ]), ConfigModule ],
|
||||||
controllers: [ GameController ],
|
controllers: [ GameController ],
|
||||||
providers: [ GameService ]
|
providers: [ GameService ]
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { ConfigService } from '@nestjs/config';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { Connection, Repository } from 'typeorm';
|
import { Connection, Repository } from 'typeorm';
|
||||||
|
|
||||||
|
import { Games } from '../games/entities/Games';
|
||||||
import { GameDetail } from './entities/GameDetail';
|
import { GameDetail } from './entities/GameDetail';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
|
@ -10,11 +11,15 @@ export class GameService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly connection: Connection,
|
private readonly connection: Connection,
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
|
@InjectRepository(Games) private readonly gamesRepository: Repository<Games>,
|
||||||
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
|
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async findOne(gameId: string) {
|
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) {
|
if (!game) {
|
||||||
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,6 @@ export class Games {
|
||||||
})
|
})
|
||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
|
|
||||||
@OneToMany(() => GameDetail, (gameDetail) => Games.gameDetail)
|
@OneToMany(() => GameDetail, (gameDetail) => gameDetail.game)
|
||||||
gameDetails: GameDetail[];
|
gameDetails: GameDetail[];
|
||||||
|
|
||||||
@ManyToOne(() => Games, (games) => games.gameDetail)
|
|
||||||
@JoinColumn([ { name: 'game_id', referencedColumnName: 'gameId' } ])
|
|
||||||
game: Games;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||||
import { GamesService } from './games.service';
|
|
||||||
|
|
||||||
|
import { GamesService } from './games.service';
|
||||||
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||||
|
|
||||||
@Controller('games')
|
@Controller('games')
|
||||||
|
|
|
||||||
18
app/api/src/player/player.controller.spec.ts
Normal file
18
app/api/src/player/player.controller.spec.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { PlayerController } from './player.controller';
|
||||||
|
|
||||||
|
describe('PlayerController', () => {
|
||||||
|
let controller: PlayerController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [PlayerController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<PlayerController>(PlayerController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
15
app/api/src/player/player.controller.ts
Normal file
15
app/api/src/player/player.controller.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import { Controller, Get, Param } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { PlayerService } from './player.service';
|
||||||
|
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||||
|
|
||||||
|
@Controller('player')
|
||||||
|
export class PlayerController {
|
||||||
|
constructor(private readonly playerService: PlayerService) {}
|
||||||
|
|
||||||
|
// /player/:playerGuid
|
||||||
|
@Get(':playerGuid')
|
||||||
|
findOne(@Param('playerGuid') playerGuid: string) {
|
||||||
|
return this.playerService.findOne(playerGuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/api/src/player/player.module.ts
Normal file
16
app/api/src/player/player.module.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
|
||||||
|
import { PlayerController } from './player.controller';
|
||||||
|
import { PlayerService } from './player.service';
|
||||||
|
|
||||||
|
import { Players } from '../players/entities/Players';
|
||||||
|
import { GameDetail } from '../game/entities/GameDetail';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [ TypeOrmModule.forFeature([ Players, GameDetail ]), ConfigModule ],
|
||||||
|
controllers: [ PlayerController ],
|
||||||
|
providers: [ PlayerService ]
|
||||||
|
})
|
||||||
|
export class PlayerModule {}
|
||||||
18
app/api/src/player/player.service.spec.ts
Normal file
18
app/api/src/player/player.service.spec.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { PlayerService } from './player.service';
|
||||||
|
|
||||||
|
describe('PlayerService', () => {
|
||||||
|
let service: PlayerService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [PlayerService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<PlayerService>(PlayerService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
28
app/api/src/player/player.service.ts
Normal file
28
app/api/src/player/player.service.ts
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Connection, Repository } from 'typeorm';
|
||||||
|
|
||||||
|
import { Players } from '../players/entities/Players';
|
||||||
|
import { GameDetail } from '../game/entities/GameDetail';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PlayerService {
|
||||||
|
constructor(
|
||||||
|
private readonly connection: Connection,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
@InjectRepository(Players) private readonly playersRepository: Repository<Players>,
|
||||||
|
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async findOne(playerGuid: string) {
|
||||||
|
const player = await this.playersRepository.findOne({
|
||||||
|
relations: [ 'gameDetails' ],
|
||||||
|
where: [ { playerGuid: playerGuid } ]
|
||||||
|
});
|
||||||
|
if (!player) {
|
||||||
|
throw new NotFoundException(`Player GUID: ${playerGuid} not found`);
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,13 +1,13 @@
|
||||||
import { Column, Entity, Index, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
import { Column, Entity, Index, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||||
import { GameDetail } from '../game/entities/GameDetail';
|
import { GameDetail } from '../../game/entities/GameDetail';
|
||||||
|
|
||||||
@Index('players_pk', [ 'playerGuid' ], { unique: true })
|
@Index('players_pk', [ 'playerGuid' ], { unique: true })
|
||||||
@Index('players_player_name_key', [ 'playerName' ], { unique: true })
|
@Index('players_player_name_key', [ 'playerName' ], { unique: true })
|
||||||
@Index('players_uuid_key', [ 'uuid' ], { unique: true })
|
@Index('players_uuid_key', [ 'uuid' ], { unique: true })
|
||||||
@Entity('players', { schema: 'public' })
|
@Entity('players', { schema: 'public' })
|
||||||
export class Players {
|
export class Players {
|
||||||
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
|
// @PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
|
||||||
id: number;
|
// id: number;
|
||||||
|
|
||||||
@Column('numeric', { primary: true, name: 'player_guid' })
|
@Column('numeric', { primary: true, name: 'player_guid' })
|
||||||
playerGuid: string;
|
playerGuid: string;
|
||||||
|
|
@ -27,19 +27,20 @@ export class Players {
|
||||||
@Column('numeric', { name: 'total_games_sctfgame', default: () => '0' })
|
@Column('numeric', { name: 'total_games_sctfgame', default: () => '0' })
|
||||||
totalGamesSctfgame: string;
|
totalGamesSctfgame: string;
|
||||||
|
|
||||||
@Column('numeric', { name: 'stat_overwrite_ctfgame', default: () => '0' })
|
@Column('numeric', { name: 'stat_overwrite_ctfgame', select: false, default: () => '0' })
|
||||||
statOverwriteCtfgame: string;
|
statOverwriteCtfgame: string;
|
||||||
|
|
||||||
@Column('numeric', { name: 'stat_overwrite_dmgame', default: () => '0' })
|
@Column('numeric', { name: 'stat_overwrite_dmgame', select: false, default: () => '0' })
|
||||||
statOverwriteDmgame: string;
|
statOverwriteDmgame: string;
|
||||||
|
|
||||||
@Column('numeric', {
|
@Column('numeric', {
|
||||||
name: 'stat_overwrite_lakrabbitgame',
|
name: 'stat_overwrite_lakrabbitgame',
|
||||||
|
select: false,
|
||||||
default: () => '0'
|
default: () => '0'
|
||||||
})
|
})
|
||||||
statOverwriteLakrabbitgame: string;
|
statOverwriteLakrabbitgame: string;
|
||||||
|
|
||||||
@Column('numeric', { name: 'stat_overwrite_sctfgame', default: () => '0' })
|
@Column('numeric', { name: 'stat_overwrite_sctfgame', select: false, default: () => '0' })
|
||||||
statOverwriteSctfgame: string;
|
statOverwriteSctfgame: string;
|
||||||
|
|
||||||
@Column('text', { name: 'uuid', unique: true })
|
@Column('text', { name: 'uuid', unique: true })
|
||||||
|
|
@ -57,6 +58,6 @@ export class Players {
|
||||||
})
|
})
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
|
|
||||||
// @OneToMany(() => GameDetail, (gameDetail) => gameDetail.playerGuid)
|
@OneToMany(() => GameDetail, (gameDetail) => gameDetail.playerGuid)
|
||||||
// gameDetails: GameDetail[];
|
gameDetails: GameDetail[];
|
||||||
}
|
}
|
||||||
18
app/api/src/players/players.controller.spec.ts
Normal file
18
app/api/src/players/players.controller.spec.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { PlayersController } from './players.controller';
|
||||||
|
|
||||||
|
describe('PlayersController', () => {
|
||||||
|
let controller: PlayersController;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
controllers: [PlayersController],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
controller = module.get<PlayersController>(PlayersController);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(controller).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
22
app/api/src/players/players.controller.ts
Normal file
22
app/api/src/players/players.controller.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
import { Controller, Get, Query, Param } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { PlayersService } from './players.service';
|
||||||
|
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||||
|
|
||||||
|
@Controller('players')
|
||||||
|
export class PlayersController {
|
||||||
|
constructor(private readonly playerService: PlayersService) {}
|
||||||
|
|
||||||
|
// /players
|
||||||
|
@Get()
|
||||||
|
findAll(@Query() paginationQuery: PaginationQueryDto) {
|
||||||
|
const { limit = 10, offset = 0 } = paginationQuery;
|
||||||
|
return this.playerService.findAll({ limit, offset });
|
||||||
|
}
|
||||||
|
|
||||||
|
// /players/:playerGuid
|
||||||
|
@Get(':playerGuid')
|
||||||
|
findOne(@Param('playerGuid') playerGuid: string) {
|
||||||
|
return this.playerService.findOne(playerGuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
app/api/src/players/players.module.ts
Normal file
16
app/api/src/players/players.module.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { ConfigModule } from '@nestjs/config';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
|
||||||
|
import { PlayersService } from './players.service';
|
||||||
|
import { PlayersController } from './players.controller';
|
||||||
|
|
||||||
|
import { Players } from './entities/Players';
|
||||||
|
import { GameDetail } from '../game/entities/GameDetail';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [ TypeOrmModule.forFeature([ Players, GameDetail ]), ConfigModule ],
|
||||||
|
providers: [ PlayersService ],
|
||||||
|
controllers: [ PlayersController ]
|
||||||
|
})
|
||||||
|
export class PlayersModule {}
|
||||||
18
app/api/src/players/players.service.spec.ts
Normal file
18
app/api/src/players/players.service.spec.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { PlayersService } from './players.service';
|
||||||
|
|
||||||
|
describe('PlayersService', () => {
|
||||||
|
let service: PlayersService;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
|
providers: [PlayersService],
|
||||||
|
}).compile();
|
||||||
|
|
||||||
|
service = module.get<PlayersService>(PlayersService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be defined', () => {
|
||||||
|
expect(service).toBeDefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
42
app/api/src/players/players.service.ts
Normal file
42
app/api/src/players/players.service.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
||||||
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Connection, Repository } from 'typeorm';
|
||||||
|
|
||||||
|
import { Players } from './entities/Players';
|
||||||
|
import { GameDetail } from '../game/entities/GameDetail';
|
||||||
|
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class PlayersService {
|
||||||
|
constructor(
|
||||||
|
private readonly connection: Connection,
|
||||||
|
private readonly configService: ConfigService,
|
||||||
|
@InjectRepository(Players) private readonly playersRepository: Repository<Players>,
|
||||||
|
@InjectRepository(GameDetail) private readonly gameRepository: Repository<GameDetail>
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async findAll(paginationQuery: PaginationQueryDto) {
|
||||||
|
const { limit, offset } = paginationQuery;
|
||||||
|
const players = await this.playersRepository.find({
|
||||||
|
skip: offset,
|
||||||
|
take: limit,
|
||||||
|
order: {
|
||||||
|
playerName: 'DESC'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return players;
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(playerGuid: string) {
|
||||||
|
const player = await this.playersRepository.findOne({
|
||||||
|
relations: [ 'gameDetails' ],
|
||||||
|
where: [ { playerGuid: playerGuid } ]
|
||||||
|
});
|
||||||
|
if (!player) {
|
||||||
|
throw new NotFoundException(`Player GUID: ${playerGuid} not found`);
|
||||||
|
}
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue