mirror of
https://github.com/amineo/t2-stat-parser.git
synced 2026-01-19 17:34:43 +00:00
init nest (wip)
This commit is contained in:
parent
1a211e261e
commit
3b5f41f933
72
app/api/.eslintrc.js
Normal file
72
app/api/.eslintrc.js
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
module.exports = {
|
||||
parser: '@typescript-eslint/parser',
|
||||
parserOptions: {
|
||||
project: 'tsconfig.json',
|
||||
sourceType: 'module'
|
||||
},
|
||||
plugins: [ '@typescript-eslint/eslint-plugin' ],
|
||||
extends: [
|
||||
'plugin:@typescript-eslint/eslint-recommended',
|
||||
'plugin:@typescript-eslint/recommended',
|
||||
'prettier',
|
||||
'prettier/@typescript-eslint'
|
||||
],
|
||||
root: true,
|
||||
env: {
|
||||
node: true,
|
||||
jest: true
|
||||
},
|
||||
rules: {
|
||||
'@typescript-eslint/interface-name-prefix': 'off',
|
||||
'@typescript-eslint/explicit-function-return-type': 'off',
|
||||
'@typescript-eslint/explicit-module-boundary-types': 'off',
|
||||
'@typescript-eslint/no-explicit-any': 'off',
|
||||
'@typescript-eslint/naming-convention': [
|
||||
'error',
|
||||
{
|
||||
selector: 'default',
|
||||
filter: {
|
||||
regex: '^(created|updated)_at$',
|
||||
match: false
|
||||
},
|
||||
format: [ 'camelCase' ],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow'
|
||||
},
|
||||
{
|
||||
selector: 'property',
|
||||
filter: {
|
||||
regex: '^(created|updated)_at$',
|
||||
match: false
|
||||
},
|
||||
format: [ 'camelCase', 'UPPER_CASE' ],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow'
|
||||
},
|
||||
{
|
||||
selector: 'enumMember',
|
||||
format: [ 'UPPER_CASE' ],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow'
|
||||
},
|
||||
{
|
||||
selector: 'variable',
|
||||
format: [ 'camelCase', 'UPPER_CASE' ],
|
||||
types: [ 'boolean', 'string', 'number', 'array' ],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow'
|
||||
},
|
||||
{
|
||||
selector: 'variable',
|
||||
format: [ 'camelCase', 'PascalCase' ],
|
||||
types: [ 'function' ],
|
||||
leadingUnderscore: 'allow',
|
||||
trailingUnderscore: 'allow'
|
||||
},
|
||||
{
|
||||
selector: 'typeLike',
|
||||
format: [ 'PascalCase' ]
|
||||
}
|
||||
]
|
||||
}
|
||||
};
|
||||
37
app/api/.gitignore
vendored
Normal file
37
app/api/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# compiled output
|
||||
/dist
|
||||
/node_modules
|
||||
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
lerna-debug.log*
|
||||
|
||||
# OS
|
||||
.DS_Store
|
||||
|
||||
# Tests
|
||||
/coverage
|
||||
/.nyc_output
|
||||
|
||||
# IDEs and editors
|
||||
/.idea
|
||||
.project
|
||||
.classpath
|
||||
.c9/
|
||||
*.launch
|
||||
.settings/
|
||||
*.sublime-workspace
|
||||
|
||||
# IDE - VSCode
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
|
||||
# ENV
|
||||
*.env
|
||||
4
app/api/.prettierrc
Normal file
4
app/api/.prettierrc
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"singleQuote": true,
|
||||
"trailingComma": "all"
|
||||
}
|
||||
75
app/api/README.md
Normal file
75
app/api/README.md
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<p align="center">
|
||||
<a href="http://nestjs.com/" target="blank"><img src="https://nestjs.com/img/logo_text.svg" width="320" alt="Nest Logo" /></a>
|
||||
</p>
|
||||
|
||||
[travis-image]: https://api.travis-ci.org/nestjs/nest.svg?branch=master
|
||||
[travis-url]: https://travis-ci.org/nestjs/nest
|
||||
[linux-image]: https://img.shields.io/travis/nestjs/nest/master.svg?label=linux
|
||||
[linux-url]: https://travis-ci.org/nestjs/nest
|
||||
|
||||
<p align="center">A progressive <a href="http://nodejs.org" target="blank">Node.js</a> framework for building efficient and scalable server-side applications, heavily inspired by <a href="https://angular.io" target="blank">Angular</a>.</p>
|
||||
<p align="center">
|
||||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/v/@nestjs/core.svg" alt="NPM Version" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/l/@nestjs/core.svg" alt="Package License" /></a>
|
||||
<a href="https://www.npmjs.com/~nestjscore"><img src="https://img.shields.io/npm/dm/@nestjs/core.svg" alt="NPM Downloads" /></a>
|
||||
<a href="https://travis-ci.org/nestjs/nest"><img src="https://api.travis-ci.org/nestjs/nest.svg?branch=master" alt="Travis" /></a>
|
||||
<a href="https://travis-ci.org/nestjs/nest"><img src="https://img.shields.io/travis/nestjs/nest/master.svg?label=linux" alt="Linux" /></a>
|
||||
<a href="https://coveralls.io/github/nestjs/nest?branch=master"><img src="https://coveralls.io/repos/github/nestjs/nest/badge.svg?branch=master#5" alt="Coverage" /></a>
|
||||
<a href="https://gitter.im/nestjs/nestjs?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=body_badge"><img src="https://badges.gitter.im/nestjs/nestjs.svg" alt="Gitter" /></a>
|
||||
<a href="https://opencollective.com/nest#backer"><img src="https://opencollective.com/nest/backers/badge.svg" alt="Backers on Open Collective" /></a>
|
||||
<a href="https://opencollective.com/nest#sponsor"><img src="https://opencollective.com/nest/sponsors/badge.svg" alt="Sponsors on Open Collective" /></a>
|
||||
<a href="https://paypal.me/kamilmysliwiec"><img src="https://img.shields.io/badge/Donate-PayPal-dc3d53.svg"/></a>
|
||||
<a href="https://twitter.com/nestframework"><img src="https://img.shields.io/twitter/follow/nestframework.svg?style=social&label=Follow"></a>
|
||||
</p>
|
||||
<!--[](https://opencollective.com/nest#backer)
|
||||
[](https://opencollective.com/nest#sponsor)-->
|
||||
|
||||
## Description
|
||||
|
||||
[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
## Running the app
|
||||
|
||||
```bash
|
||||
# development
|
||||
$ npm run start
|
||||
|
||||
# watch mode
|
||||
$ npm run start:dev
|
||||
|
||||
# production mode
|
||||
$ npm run start:prod
|
||||
```
|
||||
|
||||
## Test
|
||||
|
||||
```bash
|
||||
# unit tests
|
||||
$ npm run test
|
||||
|
||||
# e2e tests
|
||||
$ npm run test:e2e
|
||||
|
||||
# test coverage
|
||||
$ npm run test:cov
|
||||
```
|
||||
|
||||
## Support
|
||||
|
||||
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).
|
||||
|
||||
## Stay in touch
|
||||
|
||||
- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
|
||||
- Website - [https://nestjs.com](https://nestjs.com/)
|
||||
- Twitter - [@nestframework](https://twitter.com/nestframework)
|
||||
|
||||
## License
|
||||
|
||||
Nest is [MIT licensed](LICENSE).
|
||||
4
app/api/nest-cli.json
Normal file
4
app/api/nest-cli.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"collection": "@nestjs/schematics",
|
||||
"sourceRoot": "src"
|
||||
}
|
||||
78
app/api/package.json
Normal file
78
app/api/package.json
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"name": "api",
|
||||
"version": "0.0.1",
|
||||
"description": "",
|
||||
"author": "",
|
||||
"private": true,
|
||||
"license": "UNLICENSED",
|
||||
"scripts": {
|
||||
"prebuild": "rimraf dist",
|
||||
"build": "nest build",
|
||||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
|
||||
"start": "nest start",
|
||||
"start:dev": "nest start --watch",
|
||||
"start:debug": "nest start --debug --watch",
|
||||
"start:prod": "node dist/main",
|
||||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
|
||||
"test": "jest",
|
||||
"test:watch": "jest --watch",
|
||||
"test:cov": "jest --coverage",
|
||||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand",
|
||||
"test:e2e": "jest --config ./test/jest-e2e.json"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nestjs/common": "^7.0.0",
|
||||
"@nestjs/config": "^0.5.0",
|
||||
"@nestjs/core": "^7.0.0",
|
||||
"@nestjs/mapped-types": "^0.0.5",
|
||||
"@nestjs/platform-express": "^7.0.0",
|
||||
"@nestjs/swagger": "^4.5.12",
|
||||
"@nestjs/typeorm": "^7.1.0",
|
||||
"class-transformer": "^0.3.1",
|
||||
"class-validator": "^0.12.2",
|
||||
"joi": "^17.2.1",
|
||||
"pg": "^8.3.2",
|
||||
"reflect-metadata": "^0.1.13",
|
||||
"rimraf": "^3.0.2",
|
||||
"rxjs": "^6.5.4",
|
||||
"swagger-ui-express": "^4.1.4",
|
||||
"typeorm": "^0.2.25"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nestjs/cli": "^7.0.0",
|
||||
"@nestjs/schematics": "^7.0.0",
|
||||
"@nestjs/testing": "^7.0.0",
|
||||
"@types/express": "^4.17.3",
|
||||
"@types/hapi__joi": "^17.1.4",
|
||||
"@types/jest": "25.2.3",
|
||||
"@types/node": "^13.9.1",
|
||||
"@types/supertest": "^2.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "3.0.2",
|
||||
"@typescript-eslint/parser": "3.0.2",
|
||||
"eslint": "7.1.0",
|
||||
"eslint-config-prettier": "^6.10.0",
|
||||
"eslint-plugin-import": "^2.20.1",
|
||||
"jest": "26.0.1",
|
||||
"prettier": "^1.19.1",
|
||||
"supertest": "^4.0.2",
|
||||
"ts-jest": "26.1.0",
|
||||
"ts-loader": "^6.2.1",
|
||||
"ts-node": "^8.6.2",
|
||||
"tsconfig-paths": "^3.9.0",
|
||||
"typescript": "^3.7.4"
|
||||
},
|
||||
"jest": {
|
||||
"moduleFileExtensions": [
|
||||
"js",
|
||||
"json",
|
||||
"ts"
|
||||
],
|
||||
"rootDir": "src",
|
||||
"testRegex": ".spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
},
|
||||
"coverageDirectory": "../coverage",
|
||||
"testEnvironment": "node"
|
||||
}
|
||||
}
|
||||
22
app/api/src/app.controller.spec.ts
Normal file
22
app/api/src/app.controller.spec.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
describe('AppController', () => {
|
||||
let appController: AppController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const app: TestingModule = await Test.createTestingModule({
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
}).compile();
|
||||
|
||||
appController = app.get<AppController>(AppController);
|
||||
});
|
||||
|
||||
describe('root', () => {
|
||||
it('should return "Hello World!"', () => {
|
||||
expect(appController.getHello()).toBe('Hello World!');
|
||||
});
|
||||
});
|
||||
});
|
||||
12
app/api/src/app.controller.ts
Normal file
12
app/api/src/app.controller.ts
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import { Controller, Get } from '@nestjs/common';
|
||||
import { AppService } from './app.service';
|
||||
|
||||
@Controller()
|
||||
export class AppController {
|
||||
constructor(private readonly appService: AppService) {}
|
||||
|
||||
@Get()
|
||||
getHello(): string {
|
||||
return this.appService.getHello();
|
||||
}
|
||||
}
|
||||
33
app/api/src/app.module.ts
Normal file
33
app/api/src/app.module.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
import * as Joi from 'joi';
|
||||
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { GamesModule } from './games/games.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
validationSchema: Joi.object({
|
||||
DATABASE_HOST: Joi.required(),
|
||||
DATABASE_PORT: Joi.number().default(5432)
|
||||
})
|
||||
}),
|
||||
TypeOrmModule.forRoot({
|
||||
type: 'postgres', // type of our database
|
||||
host: process.env.DATABASE_HOST,
|
||||
port: +process.env.DATABASE_PORT,
|
||||
username: process.env.DATABASE_USER,
|
||||
password: process.env.DATABASE_PASSWORD,
|
||||
database: process.env.DATABASE_NAME,
|
||||
autoLoadEntities: true // models will be loaded automatically (you don't have to explicitly specify the entities: [] array)
|
||||
}),
|
||||
GamesModule
|
||||
],
|
||||
controllers: [ AppController ],
|
||||
providers: [ AppService ]
|
||||
})
|
||||
export class AppModule {}
|
||||
8
app/api/src/app.service.ts
Normal file
8
app/api/src/app.service.ts
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class AppService {
|
||||
getHello(): string {
|
||||
return 'Hello World!';
|
||||
}
|
||||
}
|
||||
11
app/api/src/common/dto/pagination-query.dto.ts
Normal file
11
app/api/src/common/dto/pagination-query.dto.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
import { IsOptional, IsPositive } from 'class-validator';
|
||||
|
||||
export class PaginationQueryDto {
|
||||
@IsOptional()
|
||||
@IsPositive()
|
||||
limit: number;
|
||||
|
||||
@IsOptional()
|
||||
@IsPositive()
|
||||
offset: number;
|
||||
}
|
||||
62
app/api/src/entities/Players.ts
Normal file
62
app/api/src/entities/Players.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import { Column, Entity, Index, OneToMany, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { GameDetail } from '../games/entities/GameDetail';
|
||||
|
||||
@Index('players_pk', [ 'playerGuid' ], { unique: true })
|
||||
@Index('players_player_name_key', [ 'playerName' ], { unique: true })
|
||||
@Index('players_uuid_key', [ 'uuid' ], { unique: true })
|
||||
@Entity('players', { schema: 'public' })
|
||||
export class Players {
|
||||
@PrimaryGeneratedColumn({ type: 'integer', name: 'id' })
|
||||
id: number;
|
||||
|
||||
@Column('numeric', { primary: true, name: 'player_guid' })
|
||||
playerGuid: string;
|
||||
|
||||
@Column('text', { name: 'player_name', unique: true })
|
||||
playerName: string;
|
||||
|
||||
@Column('numeric', { name: 'total_games_ctfgame', default: () => '0' })
|
||||
totalGamesCtfgame: string;
|
||||
|
||||
@Column('numeric', { name: 'total_games_dmgame', default: () => '0' })
|
||||
totalGamesDmgame: string;
|
||||
|
||||
@Column('numeric', { name: 'total_games_lakrabbitgame', default: () => '0' })
|
||||
totalGamesLakrabbitgame: string;
|
||||
|
||||
@Column('numeric', { name: 'total_games_sctfgame', default: () => '0' })
|
||||
totalGamesSctfgame: string;
|
||||
|
||||
@Column('numeric', { name: 'stat_overwrite_ctfgame', default: () => '0' })
|
||||
statOverwriteCtfgame: string;
|
||||
|
||||
@Column('numeric', { name: 'stat_overwrite_dmgame', default: () => '0' })
|
||||
statOverwriteDmgame: string;
|
||||
|
||||
@Column('numeric', {
|
||||
name: 'stat_overwrite_lakrabbitgame',
|
||||
default: () => '0'
|
||||
})
|
||||
statOverwriteLakrabbitgame: string;
|
||||
|
||||
@Column('numeric', { name: 'stat_overwrite_sctfgame', default: () => '0' })
|
||||
statOverwriteSctfgame: string;
|
||||
|
||||
@Column('text', { name: 'uuid', unique: true })
|
||||
uuid: string;
|
||||
|
||||
@Column('timestamp with time zone', {
|
||||
name: 'created_at',
|
||||
default: () => 'now()'
|
||||
})
|
||||
createdAt: Date;
|
||||
|
||||
@Column('timestamp with time zone', {
|
||||
name: 'updated_at',
|
||||
default: () => 'now()'
|
||||
})
|
||||
updatedAt: Date;
|
||||
|
||||
@OneToMany(() => GameDetail, (gameDetail) => gameDetail.playerGuid)
|
||||
gameDetails: GameDetail[];
|
||||
}
|
||||
46
app/api/src/games/entities/GameDetail.ts
Normal file
46
app/api/src/games/entities/GameDetail.ts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { Games } from './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;
|
||||
}
|
||||
24
app/api/src/games/entities/Games.ts
Normal file
24
app/api/src/games/entities/Games.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { Column, Entity, Index, OneToMany } from 'typeorm';
|
||||
import { GameDetail } from './GameDetail';
|
||||
|
||||
@Index('game_pk', [ 'gameId' ], { unique: true })
|
||||
@Entity('games', { schema: 'public' })
|
||||
export class Games {
|
||||
@Column('numeric', { primary: true, name: 'game_id' })
|
||||
gameId: string;
|
||||
|
||||
@Column('text', { name: 'map' })
|
||||
map: string;
|
||||
|
||||
@Column('timestamp without time zone', { name: 'datestamp' })
|
||||
datestamp: Date;
|
||||
|
||||
@Column('text', { name: 'gametype' })
|
||||
gametype: string;
|
||||
|
||||
@Column('timestamp with time zone', {
|
||||
name: 'created_at',
|
||||
default: () => 'now()'
|
||||
})
|
||||
createdAt: Date;
|
||||
}
|
||||
18
app/api/src/games/games.controller.spec.ts
Normal file
18
app/api/src/games/games.controller.spec.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GamesController } from './games.controller';
|
||||
|
||||
describe('Games Controller', () => {
|
||||
let controller: GamesController;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
controllers: [GamesController],
|
||||
}).compile();
|
||||
|
||||
controller = module.get<GamesController>(GamesController);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(controller).toBeDefined();
|
||||
});
|
||||
});
|
||||
22
app/api/src/games/games.controller.ts
Normal file
22
app/api/src/games/games.controller.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { Controller, Get, Param, Query } from '@nestjs/common';
|
||||
import { GamesService } from './games.service';
|
||||
|
||||
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||
|
||||
@Controller('games')
|
||||
export class GamesController {
|
||||
constructor(private readonly gameService: GamesService) {}
|
||||
|
||||
// /games
|
||||
@Get()
|
||||
findAll(@Query() paginationQuery: PaginationQueryDto) {
|
||||
//const { limit, offset } = paginationQuery;
|
||||
return this.gameService.findAll({ limit: 100, offset: 0 });
|
||||
}
|
||||
|
||||
// /game/:gameId
|
||||
@Get(':gameId')
|
||||
findOne(@Param('gameId') gameId: string) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
15
app/api/src/games/games.module.ts
Normal file
15
app/api/src/games/games.module.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
|
||||
import { GamesController } from './games.controller';
|
||||
import { GamesService } from './games.service';
|
||||
|
||||
import { Games } from './entities/Games';
|
||||
|
||||
@Module({
|
||||
imports: [ TypeOrmModule.forFeature([ Games ]), ConfigModule ],
|
||||
controllers: [ GamesController ],
|
||||
providers: [ GamesService ]
|
||||
})
|
||||
export class GamesModule {}
|
||||
18
app/api/src/games/games.service.spec.ts
Normal file
18
app/api/src/games/games.service.spec.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { GamesService } from './games.service';
|
||||
|
||||
describe('GamesService', () => {
|
||||
let service: GamesService;
|
||||
|
||||
beforeEach(async () => {
|
||||
const module: TestingModule = await Test.createTestingModule({
|
||||
providers: [GamesService],
|
||||
}).compile();
|
||||
|
||||
service = module.get<GamesService>(GamesService);
|
||||
});
|
||||
|
||||
it('should be defined', () => {
|
||||
expect(service).toBeDefined();
|
||||
});
|
||||
});
|
||||
26
app/api/src/games/games.service.ts
Normal file
26
app/api/src/games/games.service.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { Connection, Repository } from 'typeorm';
|
||||
|
||||
import { Games } from './entities/Games';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { PaginationQueryDto } from '../common/dto/pagination-query.dto';
|
||||
|
||||
@Injectable()
|
||||
export class GamesService {
|
||||
constructor(
|
||||
private readonly connection: Connection,
|
||||
private readonly configService: ConfigService,
|
||||
@InjectRepository(Games) private readonly gamesRepository: Repository<Games>
|
||||
) {}
|
||||
|
||||
async findAll(paginationQuery: PaginationQueryDto) {
|
||||
const { limit, offset } = paginationQuery;
|
||||
const games = await this.gamesRepository.find({
|
||||
skip: offset,
|
||||
take: limit
|
||||
});
|
||||
|
||||
return games;
|
||||
}
|
||||
}
|
||||
21
app/api/src/main.ts
Normal file
21
app/api/src/main.ts
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { NestFactory } from '@nestjs/core';
|
||||
import { ValidationPipe } from '@nestjs/common';
|
||||
import { AppModule } from './app.module';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create(AppModule);
|
||||
|
||||
app.useGlobalPipes(
|
||||
new ValidationPipe({
|
||||
whitelist: true,
|
||||
transform: true,
|
||||
forbidNonWhitelisted: true,
|
||||
transformOptions: {
|
||||
enableImplicitConversion: true
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
await app.listen(3000);
|
||||
}
|
||||
bootstrap();
|
||||
24
app/api/test/app.e2e-spec.ts
Normal file
24
app/api/test/app.e2e-spec.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { INestApplication } from '@nestjs/common';
|
||||
import * as request from 'supertest';
|
||||
import { AppModule } from './../src/app.module';
|
||||
|
||||
describe('AppController (e2e)', () => {
|
||||
let app: INestApplication;
|
||||
|
||||
beforeEach(async () => {
|
||||
const moduleFixture: TestingModule = await Test.createTestingModule({
|
||||
imports: [AppModule],
|
||||
}).compile();
|
||||
|
||||
app = moduleFixture.createNestApplication();
|
||||
await app.init();
|
||||
});
|
||||
|
||||
it('/ (GET)', () => {
|
||||
return request(app.getHttpServer())
|
||||
.get('/')
|
||||
.expect(200)
|
||||
.expect('Hello World!');
|
||||
});
|
||||
});
|
||||
9
app/api/test/jest-e2e.json
Normal file
9
app/api/test/jest-e2e.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"moduleFileExtensions": ["js", "json", "ts"],
|
||||
"rootDir": ".",
|
||||
"testEnvironment": "node",
|
||||
"testRegex": ".e2e-spec.ts$",
|
||||
"transform": {
|
||||
"^.+\\.(t|j)s$": "ts-jest"
|
||||
}
|
||||
}
|
||||
9
app/api/tsconfig.build.json
Normal file
9
app/api/tsconfig.build.json
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
"extends": "./tsconfig.json",
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"test",
|
||||
"dist",
|
||||
"**/*spec.ts"
|
||||
]
|
||||
}
|
||||
15
app/api/tsconfig.json
Normal file
15
app/api/tsconfig.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"removeComments": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"experimentalDecorators": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es2017",
|
||||
"sourceMap": true,
|
||||
"outDir": "./dist",
|
||||
"baseUrl": "./",
|
||||
"incremental": true
|
||||
}
|
||||
}
|
||||
7579
app/api/yarn.lock
Normal file
7579
app/api/yarn.lock
Normal file
File diff suppressed because it is too large
Load diff
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"rootDirs": [
|
||||
"./app/api"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue