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)
}
async getHistory (ranked: boolean): Promise<Result[]> {
async getRankedHistory (): Promise<Result[]> {
return await this.resultsRepository.find({
where: { ranked },
where: { ranked: true},
relations: {
players: true,
},
order: { date: 'DESC' }
})
}

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

@ -76,7 +76,7 @@ export class UsersController {
@Get('rankedHistory')
@UseGuards(AuthenticatedGuard)
async getRankedHistory (): Promise<Result[]> {
return await this.pongService.getHistory(true)
return await this.pongService.getRankedHistory()
}
@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);
}
async getRank(ftId: number): Promise<number> {
const leader = await this.getLeaderboard();
return leader.findIndex((user) => user.ftId === ftId);
let leaderboard = await this.usersRepository.find({
order: {
winrate: "DESC",
},
});
return leaderboard.findIndex((user) => user.ftId === ftId);
}
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>> {
let response = await fetch(API_URL + "/history/" + $store.ftId, {
let response = await fetch(API_URL + "/rankedHistory/", {
credentials: "include",
mode: "cors",
});

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

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

12
front/volume/vite.config.ts

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

Loading…
Cancel
Save