Commit 2a5dbf40 authored by Sofia Aicha Delijaj's avatar Sofia Aicha Delijaj
Browse files

showing the leaderboard

parent 2eb678e4
......@@ -108,4 +108,15 @@ exports.refuse = (req, res) => {
else res.send(data);
});
}
};
exports.wins = (req, res) => {
Joueur.wins((err, data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while retrieving Pokemon."
});
else res.send(data);
});
};
\ No newline at end of file
......@@ -95,5 +95,16 @@ Joueur.refuse = (pseudo, ami, result) => {
});
};
Joueur.wins = (result) => {
sql.query("SELECT pseudo, win from joueur ORDER BY win DESC", (err, res) => {
if (err) {
console.log("error: ", err);
result(null, err);
return;
}
result(null, res);
});
};
module.exports = Joueur;
\ No newline at end of file
......@@ -25,4 +25,7 @@ module.exports = app => {
// Logout
app.get("/logout", joueur.desAuth);
//get the descendent wins
app.get("/winners", joueur.wins);
};
\ No newline at end of file
......@@ -8,6 +8,7 @@ import { AccountMenuComponent } from './account-menu/account-menu.component';
import { ProfilComponent } from './profil/profil.component';
import { HomeComponent } from './home/home.component'
import { BattleComponent } from "./battle/battle.component";
import { LeaderboardComponent } from './leaderboard/leaderboard.component';
const routes: Routes = [
......
......@@ -22,6 +22,7 @@ import { OnlinePlayersComponent } from './sub-components/online-players/online-p
import { NotifierModule } from "angular-notifier";
import { BattleComponent } from './battle/battle.component';
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
import { LeaderboardComponent } from './leaderboard/leaderboard.component';
@NgModule({
......@@ -37,7 +38,8 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
ProfilComponent,
HomeComponent,
OnlinePlayersComponent,
BattleComponent
BattleComponent,
LeaderboardComponent
],
imports: [
BrowserModule,
......
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
......
<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/98/International_Pok%C3%A9mon_logo.svg/1200px-International_Pok%C3%A9mon_logo.svg.png" alt="Paris" class="center">
<div class="container">
<app-online-players></app-online-players>
<app-online-players></app-online-players>
<app-leaderboard></app-leaderboard>
</div>
\ No newline at end of file
<h1>Leaderboard</h1>
<div>
<table class="table">
<tr>
<th>Pseudo</th>
<th>Nombre de victoire</th>
</tr>
<tr *ngFor="let i of resultat">
<th>{{i.pseudo}}</th>
<th>{{i.win}}</th>
</tr>
</table>
</div>
\ No newline at end of file
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { LeaderboardComponent } from './leaderboard.component';
describe('LeaderboardComponent', () => {
let component: LeaderboardComponent;
let fixture: ComponentFixture<LeaderboardComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ LeaderboardComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(LeaderboardComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'app-leaderboard',
templateUrl: './leaderboard.component.html',
styleUrls: ['./leaderboard.component.css']
})
export class LeaderboardComponent implements OnInit {
constructor(private httpClient: HttpClient) { }
resultat: any = {};
ngOnInit(): void {
this.httpClient.get('http://localhost:3000/winners', { responseType: 'json', withCredentials:true }).subscribe(res => {this.resultat = res; console.log(res)})
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment