mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
Add find by endpoints
This commit is contained in:
parent
3b5f41f933
commit
2d90f9dde8
|
|
@ -10,13 +10,19 @@ export class GamesController {
|
||||||
// /games
|
// /games
|
||||||
@Get()
|
@Get()
|
||||||
findAll(@Query() paginationQuery: PaginationQueryDto) {
|
findAll(@Query() paginationQuery: PaginationQueryDto) {
|
||||||
//const { limit, offset } = paginationQuery;
|
const { limit = 10, offset = 0 } = paginationQuery;
|
||||||
return this.gameService.findAll({ limit: 100, offset: 0 });
|
return this.gameService.findAll({ limit, offset });
|
||||||
|
}
|
||||||
|
|
||||||
|
// /gametype/:gameId
|
||||||
|
@Get('gametype/:gametype')
|
||||||
|
findByType(@Param('gametype') gametype: string) {
|
||||||
|
return this.gameService.findByType(gametype);
|
||||||
}
|
}
|
||||||
|
|
||||||
// /game/:gameId
|
// /game/:gameId
|
||||||
@Get(':gameId')
|
@Get(':gameId')
|
||||||
findOne(@Param('gameId') gameId: string) {
|
findOne(@Param('gameId') gameId: string) {
|
||||||
return '';
|
return this.gameService.findOne(gameId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { Connection, Repository } from 'typeorm';
|
import { Connection, Repository } from 'typeorm';
|
||||||
|
|
||||||
|
|
@ -18,9 +18,28 @@ export class GamesService {
|
||||||
const { limit, offset } = paginationQuery;
|
const { limit, offset } = paginationQuery;
|
||||||
const games = await this.gamesRepository.find({
|
const games = await this.gamesRepository.find({
|
||||||
skip: offset,
|
skip: offset,
|
||||||
take: limit
|
take: limit,
|
||||||
|
order: {
|
||||||
|
gameId: 'DESC'
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return games;
|
return games;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async findByType(gametype: string) {
|
||||||
|
const game = await this.gamesRepository.find({ where: { gametype: gametype } });
|
||||||
|
if (!game) {
|
||||||
|
throw new NotFoundException(`Game Type: ${gametype} not found`);
|
||||||
|
}
|
||||||
|
return game;
|
||||||
|
}
|
||||||
|
|
||||||
|
async findOne(gameId: string) {
|
||||||
|
const game = await this.gamesRepository.findOne(gameId);
|
||||||
|
if (!game) {
|
||||||
|
throw new NotFoundException(`Game ID: ${gameId} not found`);
|
||||||
|
}
|
||||||
|
return game;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue