remove favorite team now working
This commit is contained in:
@@ -295,12 +295,12 @@ app.post('/favteam/add', async (req, res, next) => {
|
|||||||
});
|
});
|
||||||
app.post('/favteam/remove', async (req, res) => {
|
app.post('/favteam/remove', async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { userID, teamName } = req.body;
|
const { userID, teamID } = req.body;
|
||||||
|
|
||||||
// Check if the team exists for the user
|
// Check if the team exists for the user
|
||||||
const existingTeam = await db.oneOrNone(
|
const existingTeam = await db.oneOrNone(
|
||||||
'SELECT * FROM FavoriteTeams WHERE UserID = $1 AND TeamName = $2',
|
'SELECT * FROM FavoriteTeams WHERE UserID = $1 AND TeamID = $2',
|
||||||
[userID, teamName]
|
[userID, teamID]
|
||||||
);
|
);
|
||||||
|
|
||||||
// If the team does not exist for the user, return a 404 error
|
// If the team does not exist for the user, return a 404 error
|
||||||
@@ -310,8 +310,8 @@ app.post('/favteam/remove', async (req, res) => {
|
|||||||
|
|
||||||
// Remove the favorite team from the database
|
// Remove the favorite team from the database
|
||||||
await db.none(
|
await db.none(
|
||||||
'DELETE FROM FavoriteTeams WHERE UserID = $1 AND TeamName = $2',
|
'DELETE FROM FavoriteTeams WHERE UserID = $1 AND TeamID = $2',
|
||||||
[userID, teamName]
|
[userID, teamID]
|
||||||
);
|
);
|
||||||
|
|
||||||
console.log('Favorite team removed successfully.');
|
console.log('Favorite team removed successfully.');
|
||||||
|
|||||||
@@ -9,23 +9,9 @@ document.addEventListener("DOMContentLoaded", function() {
|
|||||||
|
|
||||||
if (favoriteButton.src.includes("/favorited.png")) {
|
if (favoriteButton.src.includes("/favorited.png")) {
|
||||||
removeFavoriteTeam(userID, teamID)
|
removeFavoriteTeam(userID, teamID)
|
||||||
.then((rmv_status) => {
|
}
|
||||||
console.log(rmv_status);
|
else {
|
||||||
if (rmv_status === 200) {
|
|
||||||
favoriteButton.src = "/img/club-page/unfavorited.png";
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error removing favorite team:', error);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addFavoriteTeam(userID, teamID, teamName, teamLogo)
|
addFavoriteTeam(userID, teamID, teamName, teamLogo)
|
||||||
.then(() => {
|
|
||||||
favoriteButton.src = "/img/club-page/favorited.png";
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
console.error('Error adding favorite team:', error);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -49,8 +35,11 @@ async function addFavoriteTeam(userID, teamID, teamName, teamLogo){
|
|||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error('Failed to add favorite team');
|
throw new Error('Failed to add favorite team');
|
||||||
}
|
}
|
||||||
|
//Changes button if favorite team is added//
|
||||||
console.log('New favorite team added successfully.');
|
console.log('New favorite team added successfully.');
|
||||||
|
var favoriteButton = document.getElementById("club-favorite-button");
|
||||||
|
favoriteButton.src = "/img/club-page/favorited.png";
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error adding favorite team:', error);
|
console.error('Error adding favorite team:', error);
|
||||||
|
|
||||||
@@ -69,6 +58,10 @@ async function removeFavoriteTeam(userID, teamID) {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
console.log('Favorite team removed successfully.');
|
console.log('Favorite team removed successfully.');
|
||||||
|
//Change button source//
|
||||||
|
var favoriteButton = document.getElementById("club-favorite-button");
|
||||||
|
favoriteButton.src = "/img/club-page/unfavorited.png";
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error removing favorite team:', error);
|
console.error('Error removing favorite team:', error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user