diff --git a/back/volume/src/pong/entity/result.entity.ts b/back/volume/src/pong/entity/result.entity.ts index 2a9eade..87ab54d 100644 --- a/back/volume/src/pong/entity/result.entity.ts +++ b/back/volume/src/pong/entity/result.entity.ts @@ -14,7 +14,7 @@ export default class Result { @PrimaryGeneratedColumn() id: number - @ManyToMany(() => User, (player: User) => player.results, { cascade: true}) + @ManyToMany(() => User, (player: User) => player.results, { cascade: true }) players: Array // TODO: change to User[] for final version @Column('text', { array: true }) diff --git a/back/volume/src/pong/game/Game.ts b/back/volume/src/pong/game/Game.ts index 219466e..7b54ada 100644 --- a/back/volume/src/pong/game/Game.ts +++ b/back/volume/src/pong/game/Game.ts @@ -16,7 +16,6 @@ import { type MapDtoValidated } from '../dtos/MapDtoValidated' import { type GameUpdate } from '../dtos/GameUpdate' import { type GameInfo } from '../dtos/GameInfo' import { type PongService } from '../pong.service' -import { Injectable, Inject } from '@nestjs/common' function gameLoop (game: Game): void { const canvasRect: Rect = new Rect( @@ -34,7 +33,7 @@ function gameLoop (game: Game): void { game.players[indexPlayerScored].score += 1 if (game.players[indexPlayerScored].score >= DEFAULT_WIN_SCORE) { console.log(`${game.players[indexPlayerScored].name} won!`) - game.stop() + void game.stop() } } @@ -116,7 +115,7 @@ export class Game { if (playerIndex !== -1) { this.players.splice(playerIndex, 1) if (this.players.length < 2) { - this.stop() + void this.stop() } } } diff --git a/back/volume/src/pong/pong.module.ts b/back/volume/src/pong/pong.module.ts index 594383b..821acbb 100644 --- a/back/volume/src/pong/pong.module.ts +++ b/back/volume/src/pong/pong.module.ts @@ -6,9 +6,7 @@ import { PongService } from './pong.service' import { UsersModule } from 'src/users/users.module' @Module({ - imports: [ - forwardRef(() => UsersModule), - TypeOrmModule.forFeature([Result])], + imports: [forwardRef(() => UsersModule), TypeOrmModule.forFeature([Result])], providers: [PongGateway, PongService], exports: [PongService] }) diff --git a/back/volume/src/pong/pong.service.ts b/back/volume/src/pong/pong.service.ts index 45f44c8..5b0ba84 100644 --- a/back/volume/src/pong/pong.service.ts +++ b/back/volume/src/pong/pong.service.ts @@ -1,4 +1,4 @@ -import { Inject, Injectable, forwardRef } from '@nestjs/common' +import { Injectable } from '@nestjs/common' import { InjectRepository } from '@nestjs/typeorm' import { Repository } from 'typeorm' import { UsersService } from 'src/users/users.service' @@ -14,28 +14,28 @@ export class PongService { private readonly usersService: UsersService ) {} - async updatePlayer (i: number, result: Result) { + async updatePlayer (i: number, result: Result): Promise { const player: User | null = result.players[i] if (player == null) return player.matchs++ if (result.score[i] > result.score[Math.abs(i - 1)]) player.wins++ else player.looses++ player.winrate = (100 * player.wins) / player.matchs - player.rank = await this.usersService.getRank(player.ftId) + 1 - //player.results.push(result) + player.rank = (await this.usersService.getRank(player.ftId)) + 1 + // player.results.push(result) this.usersService.save(player) } - async saveResult (players: Player[]) { - let result = new Result() - let ply = new Array + async saveResult (players: Player[]): Promise { + const result = new Result() + const ply = new Array() ply.push(await this.usersService.findUserByName(players[0].name)) ply.push(await this.usersService.findUserByName(players[1].name)) - result.players = ply; + result.players = ply result.score = [players[0].score, players[1].score] - this.resultsRepository.save(result) - this.updatePlayer(0, result) - this.updatePlayer(1, result) + await this.resultsRepository.save(result) + await this.updatePlayer(0, result) + await this.updatePlayer(1, result) } async getHistory (): Promise { @@ -48,5 +48,4 @@ export class PongService { const results = await this.usersService.getResults(ftId) return results.sort((a, b) => (a.date < b.date ? 1 : -1)) } - } diff --git a/back/volume/src/types.d.ts b/back/volume/src/types.d.ts index afe5375..0f5d664 100644 --- a/back/volume/src/types.d.ts +++ b/back/volume/src/types.d.ts @@ -1,5 +1,5 @@ declare module 'passport-42' { export type Profile = any export type VerifyCallback = any - export class Strategy {} + export class Strategy {}! } diff --git a/back/volume/src/users/users.controller.ts b/back/volume/src/users/users.controller.ts index 81c5f14..ad7d1fa 100644 --- a/back/volume/src/users/users.controller.ts +++ b/back/volume/src/users/users.controller.ts @@ -11,7 +11,8 @@ import { Res, StreamableFile, BadRequestException, - Redirect + Redirect, + type NotFoundException } from '@nestjs/common' import { FileInterceptor } from '@nestjs/platform-express' @@ -30,59 +31,59 @@ import { ApiBody, ApiConsumes } from '@nestjs/swagger' import { type Request, Response } from 'express' import { createReadStream } from 'fs' import { join } from 'path' +import type Result from 'src/pong/entity/result.entity' @Controller() export class UsersController { - constructor( + constructor ( private readonly usersService: UsersService, private readonly pongService: PongService - ) { } + ) {} @Get('all') - async getAllUsers(): Promise { + async getAllUsers (): Promise { return await this.usersService.findUsers() } @Get('online') - async getOnlineUsers(): Promise { + async getOnlineUsers (): Promise { return await this.usersService.findOnlineUsers() } @Get('friends') @UseGuards(AuthenticatedGuard) - async getFriends(@FtUser() profile: Profile) { + async getFriends (@FtUser() profile: Profile): Promise { return await this.usersService.getFriends(profile.id) } @Get('invits') @UseGuards(AuthenticatedGuard) - async getInvits(@FtUser() profile: Profile) { + async getInvits (@FtUser() profile: Profile): Promise { return await this.usersService.getInvits(profile.id) } - @Get('leader') @UseGuards(AuthenticatedGuard) - async getLeader() { + async getLeader (): Promise { return await this.usersService.getLeader() } @Get('leader/:id') @UseGuards(AuthenticatedGuard) - async getRank(@Param('id', ParseIntPipe) id: number) { + async getRank (@Param('id', ParseIntPipe) id: number): Promise { return await this.usersService.getRank(id) } @Get('history') @UseGuards(AuthenticatedGuard) - async getHistory() { + async getHistory (): Promise { return await this.pongService.getHistory() } @Get('history/:id') @UseGuards(AuthenticatedGuard) - async getHistoryById(@Param('id', ParseIntPipe) id: number) { - return this.pongService.getHistoryById(id) + async getHistoryById (@Param('id', ParseIntPipe) id: number): Promise { + return await this.pongService.getHistoryById(id) } @Post('avatar') @@ -107,43 +108,43 @@ export class UsersController { description: 'A new avatar for the user', type: AvatarUploadDto }) - async addAvatar( + async addAvatar ( @FtUser() profile: Profile, - @UploadedFile() file: Express.Multer.File - ) { + @UploadedFile() file: Express.Multer.File + ): Promise { await this.usersService.addAvatar(profile.id, file.filename) } @Get('avatar') @UseGuards(AuthenticatedGuard) - async getAvatar( + async getAvatar ( @FtUser() profile: Profile, - @Res({ passthrough: true }) response: Response - ) { + @Res({ passthrough: true }) response: Response + ): Promise { return await this.getAvatarById(profile.id, response) } @Get('user/:name') - async getUserByName(@Param('name') username: string): Promise { + async getUserByName (@Param('name') username: string): Promise { return await this.usersService.findUserByName(username) } @Get('invit/:id') @UseGuards(AuthenticatedGuard) - async invitUser( + async invitUser ( @FtUser() profile: Profile, - @Param('id', ParseIntPipe) id: number - ) { + @Param('id', ParseIntPipe) id: number + ): Promise { return await this.usersService.invit(profile.id, id) } @Get('avatar/:id') - async getAvatarById( + async getAvatarById ( @Param('id', ParseIntPipe) ftId: number, - @Res({ passthrough: true }) response: Response - ) { + @Res({ passthrough: true }) response: Response + ): Promise { const user = await this.usersService.findUser(ftId) - if (user == null) return + if (user == null) return null const filename = user.avatar const stream = createReadStream(join(process.cwd(), 'avatars/' + filename)) response.set({ @@ -154,15 +155,15 @@ export class UsersController { } @Get(':id') - async getUserById( + async getUserById ( @Param('id', ParseIntPipe) ftId: number ): Promise { return await this.usersService.findUser(ftId) } - @Post(":id") + @Post(':id') @UseGuards(AuthenticatedGuard) - async createById(@Body() payload: UserDto) { + async createById (@Body() payload: UserDto): Promise { const user = await this.usersService.findUser(payload.ftId) if (user != null) { return await this.usersService.update(user, payload) @@ -173,13 +174,13 @@ export class UsersController { @Get() @UseGuards(AuthenticatedGuard) - async getUser(@FtUser() profile: Profile): Promise { + async getUser (@FtUser() profile: Profile): Promise { return await this.usersService.findUser(profile.id) } @Post() @UseGuards(AuthenticatedGuard) - async create(@Body() payload: UserDto, @FtUser() profile: Profile) { + async create (@Body() payload: UserDto, @FtUser() profile: Profile): Promise { const user = await this.usersService.findUser(profile.id) if (user != null) { return await this.usersService.update(user, payload) @@ -187,5 +188,4 @@ export class UsersController { return await this.usersService.create(payload) } } - } diff --git a/back/volume/src/users/users.module.ts b/back/volume/src/users/users.module.ts index 3a1b851..f4f5190 100644 --- a/back/volume/src/users/users.module.ts +++ b/back/volume/src/users/users.module.ts @@ -6,11 +6,9 @@ import { UsersService } from './users.service' import { PongModule } from 'src/pong/pong.module' @Module({ - imports: [ - forwardRef(() => PongModule), - TypeOrmModule.forFeature([User])], + imports: [forwardRef(() => PongModule), TypeOrmModule.forFeature([User])], controllers: [UsersController], providers: [UsersService], exports: [UsersService] }) -export class UsersModule { } +export class UsersModule {} diff --git a/back/volume/src/users/users.service.ts b/back/volume/src/users/users.service.ts index fdda2eb..cc318b1 100644 --- a/back/volume/src/users/users.service.ts +++ b/back/volume/src/users/users.service.ts @@ -4,13 +4,13 @@ import { EntityNotFoundError, QueryFailedError, Repository } from 'typeorm' import { User } from './entity/user.entity' import { type UserDto } from './dto/user.dto' import { type Channel } from 'src/chat/entity/channel.entity' -import Result from 'src/pong/entity/result.entity' +import type Result from 'src/pong/entity/result.entity' @Injectable() @Catch(QueryFailedError, EntityNotFoundError) export class UsersService { constructor ( - @InjectRepository(User) private readonly usersRepository: Repository, + @InjectRepository(User) private readonly usersRepository: Repository ) {} save (user: User) { diff --git a/front/volume/src/components/Pong/Ball.ts b/front/volume/src/components/Pong/Ball.ts index d4e621a..00ef960 100644 --- a/front/volume/src/components/Pong/Ball.ts +++ b/front/volume/src/components/Pong/Ball.ts @@ -4,10 +4,7 @@ export class Ball { rect: Rect; speed: Point; - constructor( - spawn: Point, - size: Point = new Point(20, 20) - ) { + constructor(spawn: Point, size: Point = new Point(20, 20)) { this.rect = new Rect(spawn, size); } diff --git a/front/volume/src/components/Pong/ColorPicker.svelte b/front/volume/src/components/Pong/ColorPicker.svelte index 94fee35..6bd6d9a 100644 --- a/front/volume/src/components/Pong/ColorPicker.svelte +++ b/front/volume/src/components/Pong/ColorPicker.svelte @@ -3,7 +3,7 @@
- +