Skip to content
Snippets Groups Projects
Commit 2a505554 authored by Haoyu Sun's avatar Haoyu Sun
Browse files

matchDetailChangeScore

parent 04072d2c
No related branches found
No related tags found
5 merge requests!51Resolves 64,!49Resolve issue 70,!48Resolve issue 70,!47Revert "Merge branch '26-as-a-user-i-want-to-see-the-rankings-of-each-member' into 'main'",!29Resolve "As a user, I want to see the match details and be able to change my score"
loadNavbar('navbar-container');
loadFooter('footer-container');
const urlParams = new URLSearchParams(window.location.search);
const matchId = urlParams.get('id');
async function fetchMatchDetails(id) {
try {
const response = await fetch(`/match/${id}`);
const matchData = await response.json();
document.getElementById('sport').value = matchData.sport;
document.getElementById('playerAId').value = matchData.playerAId;
document.getElementById('playerBId').value = matchData.playerBId;
document.getElementById('planTime').value = matchData.planTime;
document.getElementById('status').value = matchData.status;
document.getElementById('scoreA').value = matchData.scoreA;
document.getElementById('scoreB').value = matchData.scoreB;
document.getElementById('confirmByA').checked = matchData.confirmByA;
document.getElementById('confirmByB').checked = matchData.confirmByB;
document.getElementById('winnerId').value = matchData.winnerId;
// document.getElementById('scoreA').value = matchData.scoreA;
// document.getElementById('scoreB').value = matchData.scoreB;
// document.getElementById('winnerId').value = matchData.winnerId ? matchData.winnerId : '';
} catch (error) {
console.error('Error fetching match details:', error);
}
}
document.getElementById('updateMatchForm').addEventListener('submit', async function(event) {
// prevent evnts
event.preventDefault();
const updatedMatch = {
sport: document.getElementById('sport').value,
player_AId: document.getElementById('playerAId').value,
player_BId: document.getElementById('playerBId').value,
plan_Time: document.getElementById('planTime').value,
status: document.getElementById('status').value,
scoreA: document.getElementById('scoreA').value,
scoreB: document.getElementById('scoreB').value,
confirm_a: document.getElementById('confirmByA').checked,
confirm_b: document.getElementById('confirmByB').checked,
winnerId: document.getElementById('winnerId').value
};
try {
const res = await fetch(`/match/${matchId}`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(updatedMatch)
});
if (res.ok) {
alert('Match updated successfully');
window.location.href = `/html/matchDetail.html?id=${matchId}`;
} else {
alert('Failed to update match');
}
} catch (err) {
console.error('error updating match:', err);
alert('error updating match');
}
});
fetchMatchDetails(matchId);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment