Browse Source

history and leaderboard fix

master
nicolas-arnaud 2 years ago
parent
commit
d909b9d4f6
  1. 7
      back/volume/src/pong/pong.service.ts
  2. 2
      back/volume/src/users/users.controller.ts
  3. 9
      back/volume/src/users/users.service.ts
  4. 2
      front/volume/src/App.svelte
  5. 1
      front/volume/src/components/MatchHistory.svelte
  6. 12
      front/volume/vite.config.ts

7
back/volume/src/pong/pong.service.ts

@ -49,9 +49,12 @@ export class PongService {
await this.updatePlayer(1, result) await this.updatePlayer(1, result)
} }
async getHistory (ranked: boolean): Promise<Result[]> { async getRankedHistory (): Promise<Result[]> {
return await this.resultsRepository.find({ return await this.resultsRepository.find({
where: { ranked }, where: { ranked: true},
relations: {
players: true,
},
order: { date: 'DESC' } order: { date: 'DESC' }
}) })
} }

2
back/volume/src/users/users.controller.ts

@ -76,7 +76,7 @@ export class UsersController {
@Get('rankedHistory') @Get('rankedHistory')
@UseGuards(AuthenticatedGuard) @UseGuards(AuthenticatedGuard)
async getRankedHistory (): Promise<Result[]> { async getRankedHistory (): Promise<Result[]> {
return await this.pongService.getHistory(true) return await this.pongService.getRankedHistory()
} }
@Get('history/:id') @Get('history/:id')

9
back/volume/src/users/users.service.ts

@ -131,12 +131,15 @@ export class UsersService {
}, },
}); });
return leaderboard.filter((user) => user.rank !== 0); return leaderboard.filter((user) => user.rank !== 0);
} }
async getRank(ftId: number): Promise<number> { async getRank(ftId: number): Promise<number> {
const leader = await this.getLeaderboard(); let leaderboard = await this.usersRepository.find({
return leader.findIndex((user) => user.ftId === ftId); order: {
winrate: "DESC",
},
});
return leaderboard.findIndex((user) => user.ftId === ftId);
} }
async invit(ftId: number, targetFtId: number): Promise<void> { async invit(ftId: number, targetFtId: number): Promise<void> {

2
front/volume/src/App.svelte

@ -87,7 +87,7 @@
} }
export async function getHistory(): Promise<Array<Match>> { export async function getHistory(): Promise<Array<Match>> {
let response = await fetch(API_URL + "/history/" + $store.ftId, { let response = await fetch(API_URL + "/rankedHistory/", {
credentials: "include", credentials: "include",
mode: "cors", mode: "cors",
}); });

1
front/volume/src/components/MatchHistory.svelte

@ -4,6 +4,7 @@
players: Array<Player>; players: Array<Player>;
score: Array<number>; score: Array<number>;
date: Date; date: Date;
ranked: boolean;
} }
</script> </script>

12
front/volume/vite.config.ts

@ -1,13 +1,13 @@
import { defineConfig } from 'vite' import { defineConfig } from "vite";
import { svelte } from '@sveltejs/vite-plugin-svelte' import { svelte } from "@sveltejs/vite-plugin-svelte";
// https://vitejs.dev/config/
export default defineConfig({ export default defineConfig({
plugins: [svelte()], plugins: [svelte()],
appType: "spa",
server: { server: {
port: 80 port: 80,
}, },
preview: { preview: {
port: 80 port: 80,
}, },
}) });

Loading…
Cancel
Save