ça marche pu

This commit is contained in:
Allan Cueff
2023-11-07 21:57:57 +01:00
parent 9ec2cab3ed
commit 8b26489a6d

View File

@@ -11,7 +11,6 @@ const data = {
const record = await pb.collection('match').update(idMatch, data);
//Récupération des données du match
const currentStatus = await pb.collection('match').getOne(idMatch, {
expand: 'sport,team1,team2',
@@ -21,6 +20,10 @@ const EquipeList = await pb.collection('equipes').getFullList({
expand: 'promo,sport',
});
const MatchList = await pb.collection('match').getFullList({
filter: `team1 = ${currentStatus.team1}|| team2 = ${currentStatus.team1}|| team1 = ${currentStatus.team2}|| team2 = ${currentStatus.team2}`,
});
//Affichage des données initial du match
const textPoint1 = document.getElementById("textPoint1")
const textPoint2 = document.getElementById("textPoint2")
@@ -365,7 +368,18 @@ async function setTeamClassement(sportId){
sportTeams.push(equipe)//On sélectionne toutes les équipes du sport indiqué en paramètres
}
})
sportTeams.sort((teamA, teamB) => parseInt(teamB.points, 10) - parseInt(teamA.points, 10))//On range les équipes par ordre de points décroissant
sportTeams.sort((teamA, teamB) => {
let diff = parseInt(teamB.points, 10) - parseInt(teamA.points, 10)
if(diff !== 0){
return diff;
} else {
try{
return goalsDiff(teamA, teamB);
} catch {
return 0;
}
}
})//On range les équipes par ordre de points décroissant
for(let i = 1; i <= sportTeams.length; i++){
const data = {
"classement": i,
@@ -393,4 +407,24 @@ async function promoteNextStade(teamId){
}
}
function goalsDiff(teamA, teamB){
let totalA = 0
let totalB = 0
MatchList.forEach(match => {
if(match.team1 = teamA.id){
totalA += match.point1
}
if(match.team2 = teamA.id){
totalA += match.point2
}
if(match.team1 = teamB.id){
totalB += match.point1
}
if(match.team2 = teamB.id){
totalB += match.point2
}
})
return totalB - totalA
}
console.log("Backend arbitrage loaded!");