Commit c0e4f6dd authored by Sofia Aicha Delijaj's avatar Sofia Aicha Delijaj
Browse files

popular uwu?

parent 2a5dbf40
......@@ -84,4 +84,14 @@ exports.remove = (req, res) => {
}
} else res.send({ message: `Pokemon was deleted successfully from Team!` });
});
};
exports.popular = (req, res) => {
Pokemon.mostUsed((err, data) => {
if (err)
res.status(500).send({
message: err.message || "Some error occurred while retrieving the bests."
});
else res.send(data);
});
};
\ No newline at end of file
......@@ -23,6 +23,17 @@ Pokemon.getAll = result => {
});
};
Pokemon.mostUsed = result => {
sql.query("SELECT pokeName, COUNT(*) as number FROM pokemon, team WHERE team.id_pokemon = pokemon.id_pokemon AND courant = 1 GROUP BY team.id_pokemon ORDER BY number DESC", (err, res) => {
if (err) {
console.log("error: ", err);
result(null, err);
return;
}
result(null, res);
});
};
// Pokemon.getTeamUtil = (joueur_id, result) => {
// sql.query('SELECT p.*, m.* FROM pokemon as p, team, moveUtil as mu, move as m WHERE id_joueur= ? AND p.id_pokemon=team.id_pokemon AND mu.move_id=m.id_move AND mu.pokemon_id=p.id_pokemon;', [joueur_id], (err, res) => {
......
......@@ -15,4 +15,7 @@ module.exports = app => {
app.post("/updatemove", pokemon.updateMove);
//get the pokemons most present in teams
app.get("/popular", pokemon.popular);
};
\ No newline at end of file
......@@ -10,4 +10,14 @@
<th>{{i.win}}</th>
</tr>
</table>
<table class="table">
<tr>
<th>Pokemon</th>
<th>Nombre d'apparition </th>
</tr>
<tr *ngFor="let j of poke">
<th>{{j.pokeName}}</th>
<th>{{j.number}}</th>
</tr>
</table>
</div>
\ No newline at end of file
......@@ -11,9 +11,11 @@ export class LeaderboardComponent implements OnInit {
constructor(private httpClient: HttpClient) { }
resultat: any = {};
poke:any = {};
ngOnInit(): void {
this.httpClient.get('http://localhost:3000/winners', { responseType: 'json', withCredentials:true }).subscribe(res => {this.resultat = res; console.log(res)})
this.httpClient.get('http://localhost:3000/winners', { responseType: 'json', withCredentials:true }).subscribe(res => {this.resultat = res})
this.httpClient.get('http://localhost:3000/popular', { responseType: 'json', withCredentials:true }).subscribe(res => {this.poke = 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