Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Player Rating Endpoints #8

Merged
merged 42 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
b76c1b1
feat: add rating endpoints
invaderb May 6, 2023
c5e2ded
fix: comment typos
invaderb May 6, 2023
bb975a1
fix: select values
invaderb May 6, 2023
afa5960
fix: swagger docs
invaderb May 6, 2023
fd90775
chore: remove unneeded console.log
invaderb May 6, 2023
4061bf0
chore: code clean up and refactor
invaderb May 6, 2023
f84439e
chore: code clean up
invaderb May 6, 2023
d995461
chore: code clean up
invaderb May 6, 2023
ebd3001
Merge branch 'dev' into rating-endpoints
invaderb May 6, 2023
0a92cf2
test: fix game service tests
invaderb May 6, 2023
7fb5c6e
Merge branch 'rating-endpoints' of github.com:USTakAssociation/playta…
invaderb May 6, 2023
b94a5d1
chore[Readme]: make endpoints list more readable
nitzel Apr 30, 2023
f05b892
fix: use path.join to prevent misconfigurations of e.g. DB_PATH when …
nitzel Apr 30, 2023
02cb12a
Merge branch 'rating-endpoints' of github.com:USTakAssociation/playta…
invaderb May 6, 2023
a7b6dbe
feat: add rating endpoints
invaderb May 6, 2023
515846e
fix: comment typos
invaderb May 6, 2023
eac25a0
fix: select values
invaderb May 6, 2023
7d97697
fix: swagger docs
invaderb May 6, 2023
5f44a78
chore: remove unneeded console.log
invaderb May 6, 2023
45ad58c
chore: code clean up and refactor
invaderb May 6, 2023
a6242b1
chore: code clean up
invaderb May 6, 2023
f22056f
chore: code clean up
invaderb May 6, 2023
bfb4264
test: fix game service tests
invaderb May 6, 2023
707a1cb
Merge branch 'rating-endpoints' of github.com:USTakAssociation/playta…
invaderb May 6, 2023
e082bc5
feat: add rating endpoints
invaderb May 6, 2023
dbf940e
chore: code clean up
invaderb May 6, 2023
54ff1fe
chore: code clean up
invaderb May 6, 2023
63de9b8
Merge branch 'rating-endpoints' of github.com:USTakAssociation/playta…
invaderb May 6, 2023
0e85a5c
fix: issues from rebasing
invaderb May 6, 2023
b81caf2
chore: code clean up and refactor
invaderb May 15, 2023
1f95973
fix: spelling error
invaderb May 16, 2023
9e767e0
fix: readme endpoints
invaderb Dec 22, 2023
c92d515
Merge branch 'dev' into rating-endpoints
invaderb Jun 18, 2024
6651a0a
Merge branch 'dev' into rating-endpoints
invaderb Jun 18, 2024
bb86af3
feat: add bru api test files
invaderb Jun 18, 2024
0194c27
fix: fatigue rating calculation
invaderb Jun 19, 2024
fc03290
fix: unit test for updated typings
invaderb Jun 19, 2024
fa73f96
fix: typos
invaderb Jun 19, 2024
249f7dc
chore: update readme
invaderb Jun 19, 2024
84f152c
fix: logic for always adding fatiguerating to players who have or hav…
invaderb Jun 19, 2024
5631f3c
fix: add cron directive
invaderb Jun 19, 2024
bd77c31
fix: update deploy script
invaderb Jun 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ NODE_ENV=local
APP_ENV=Local
CORS_DOMAIN=*
ANON_DB_PATH=/Users/braydonharris/dev/personal-projects/tak/server/games_anon.db
DIST_PATH=dist/
DIST_PATH=dist/
PREVIOUS_FILE=previous.txt
invaderb marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 1 addition & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ name: Play Tak API CI

on:
pull_request:
types:
- opened
branches:
- main
- dev

jobs:
lint_and_test:
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
ANON_DB_PATH: ${{ secrets.ANON_DB_PATH }}
DB_PATH: ${{ secrets.DB_PATH }}
APP_ENV: ${{ secrets.APP_ENV }}
PREVIOUS_FILE: ${{ secrets.PREVIOUS_FILE }}
run : |
rm .env
touch .env
Expand All @@ -53,8 +54,10 @@ jobs:
echo "ANON_DB_PATH = ${ANON_DB_PATH}" >> .env
echo "DB_PATH = ${DB_PATH}" >> .env
echo "APP_ENV = ${APP_ENV}" >> .env
echo "PREVIOUS_FILE = ${PREVIOUS_FILE}" >> .env
mv .env ./dist
mv node_modules ./dist
mv previous.txt ./dist
tar -czf artifact.tar.gz ./dist
- name: Deploy
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/deploy-prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
ANON_DB_PATH: ${{ secrets.ANON_DB_PATH }}
DB_PATH: ${{ secrets.DB_PATH }}
APP_ENV: ${{ secrets.APP_ENV }}
PREVIOUS_FILE: ${{ secrets.PREVIOUS_FILE }}
run : |
rm .env
touch .env
Expand All @@ -53,6 +54,7 @@ jobs:
echo "ANON_DB_PATH = ${ANON_DB_PATH}" >> .env
echo "DB_PATH = ${DB_PATH}" >> .env
echo "APP_ENV = ${APP_ENV}" >> .env
echo "PREVIOUS_FILE = ${PREVIOUS_FILE}" >> .env
mv .env ./dist
mv node_modules ./dist
tar -czf artifact.tar.gz ./dist
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

## Description

![Unit Tests](https://github.com/USTakAssociation/playtak-api/actions/workflows/ci.yml/badge.svg
)
![Unit Tests](https://github.com/USTakAssociation/playtak-api/actions/workflows/ci.yml/badge.svg)


This is the Play Tak API projects which contains multiple endpoints for serivcing data to the Play Tak UI
Expand Down Expand Up @@ -53,6 +52,12 @@ https://api.{env}.playtak.com
- /v1/games-historoy/ptn/{id}
- /v1/hames-history/db

- /v1/ratings
- /v1/ratings{player_name}

- /v1/ratings
- /v1/ratings{player_name}
invaderb marked this conversation as resolved.
Show resolved Hide resolved

## TODO

- Finish up migrating rerating to nest
Expand Down
53 changes: 53 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@nestjs/config": "^2.2.0",
"@nestjs/core": "^9.2.1",
"@nestjs/platform-fastify": "^9.2.1",
"@nestjs/schedule": "^2.2.1",
"@nestjs/swagger": "^6.3.0",
"@nestjs/throttler": "^3.1.0",
"@nestjs/typeorm": "^9.0.1",
Expand Down
1 change: 1 addition & 0 deletions previous.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
547436 hash
invaderb marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 14 additions & 2 deletions src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,43 @@
/* istanbul ignore file */
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ThrottlerGuard } from '@nestjs/throttler';
import { APP_GUARD } from '@nestjs/core';
import { EventsModule } from './models/events/events.module';
import { GamesModule } from './models/games-history/games.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RatingsModule } from './models/ratings/ratings.module';
import { ScheduleModule } from '@nestjs/schedule';
import * as path from 'path';


@Module({
imports: [
ConfigModule.forRoot(),
TypeOrmModule.forRoot({
name: 'games',
type: 'sqlite',
database: path.join(process.env.DB_PATH, 'games.db'),
entities: [path.join(__dirname, '/**/*.entity{.ts,.js}')],
synchronize: false,
}),
TypeOrmModule.forRoot({
name: 'default',
invaderb marked this conversation as resolved.
Show resolved Hide resolved
type: 'sqlite',
database: path.join(process.env.DB_PATH, 'players.db'),
entities: [path.join(__dirname, '/**/*.entity{.ts,.js}')],
synchronize: false,
}),
ScheduleModule.forRoot(),
EventsModule,
GamesModule,
RatingsModule,
],
controllers: [],
providers: [
{
provide: APP_GUARD,
useClass: ThrottlerGuard,
}
},
],
})
export class AppModule {}
6 changes: 1 addition & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import {
Expand All @@ -22,11 +23,6 @@ async function bootstrap() {
});

const config = new DocumentBuilder()
.addApiKey({
invaderb marked this conversation as resolved.
Show resolved Hide resolved
type: 'apiKey',
name: 'Ocp-Apim-Subscription-Key',
in: 'header',
})
.setTitle(`Play Tak API Service ${process.env.APP_ENV}`)
.setDescription('Play Tak API Service Swagger API documentation')
.setVersion('1.0')
Expand Down
1 change: 1 addition & 0 deletions src/models/events/events.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import { CacheInterceptor, CacheModule, Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { ThrottlerModule } from '@nestjs/throttler';
Expand Down
3 changes: 2 additions & 1 deletion src/models/games-history/games.module.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* istanbul ignore file */
import { Module } from '@nestjs/common';
import { ThrottlerModule } from '@nestjs/throttler';
import { TypeOrmModule } from '@nestjs/typeorm';
Expand All @@ -9,7 +10,7 @@ import { PTNService } from './services/ptn.service';
@Module({
controllers: [GamesController],
imports: [
TypeOrmModule.forFeature([Games]),
TypeOrmModule.forFeature([Games], 'games'),
ThrottlerModule.forRootAsync({
useFactory: () => ({
ttl: 60,
Expand Down
2 changes: 1 addition & 1 deletion src/models/games-history/games.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('GamesService', () => {
GamesService,
PTNService,
{
provide: getRepositoryToken(Games),
provide: getRepositoryToken(Games, 'games'),
useValue: mockRepo,
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/models/games-history/games.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { GameQuery } from './dto/games.dto';
@Injectable()
export class GamesService {
constructor(
@InjectRepository(Games)
@InjectRepository(Games, 'games')
private repository: Repository<Games>,
private ptnSerivce: PTNService,
) {}
Expand Down
13 changes: 13 additions & 0 deletions src/models/ratings/dto/error.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/* eslint-disable indent */
import { ApiProperty } from '@nestjs/swagger';

export class DefaultExceptionDto {
@ApiProperty()
statusCode: number;

@ApiProperty()
message: string;

@ApiProperty()
error: string;
}
68 changes: 68 additions & 0 deletions src/models/ratings/dto/ratings.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { ApiProperty } from "@nestjs/swagger";
export class Rating {
@ApiProperty()
id: number;
@ApiProperty()
name: string;
@ApiProperty()
rating: number;
@ApiProperty()
maxrating: number;
@ApiProperty()
ratedgames: number;
@ApiProperty()
isbot: boolean;
}

export class RatingList {
@ApiProperty()
items: Array<Rating>;
@ApiProperty()
total: number;
@ApiProperty()
perPage: number;
@ApiProperty()
page: number;
@ApiProperty()
totalPages: number;
}

export class RatingQuery {
@ApiProperty({
description: 'Number of results per pag for pagination. Optional.',
humanat marked this conversation as resolved.
Show resolved Hide resolved
required: false
})
limit?: string;
invaderb marked this conversation as resolved.
Show resolved Hide resolved
@ApiProperty({
description: 'Page number for pagination. Optional.',
required: false
})
page?: string;
@ApiProperty({
description: 'Number of items to skip for pagination. Can use this instead of a page number. Optional.',
required: false,
})
skip?: string;
@ApiProperty({
description: 'Order By either ASC or DESC for sorting. Optional.',
enum: ['ASC', 'DESC'],
required: false
})
order?: 'ASC' | 'DESC';
@ApiProperty({
description: 'Which column to sort by for sorting. Optional.',
required: false
})
sort?: string;
@ApiProperty({
description: 'Player ID. Optional.',
required: false
})
id?: number;
@ApiProperty({
description: 'Player username. Optional.',
required: false
})
name?: string;
}

Loading