When the user clicks on the business name it needs to be saved as its favorite, taking the businessID and userID and insert it into the database. The backend is ready to get the post request but I have not figured out how to send that data.
This is the code I have been using to get the favorite business with the userid and businessid (In the backend there is a query that SELECT * from business etc...)
How can I change this code to make a POST request instead? (inserting a new fav business) Assuming in the backend there is a query with the INSERT INTO ....)
saveBusiness = (e) => {
fetch("http://localhost:3030/favbusiness/" + this.state.selectedUserid + "/" + this.state.selectedBusiness)
.then((response) => {
return response.json();
})
.then(data => {
let favBusinessFromApi = data.map(favorite => {
return { value: favorite.businessid }
});
this.setState({
favoriteBusiness: favBusinessFromApi
});
.catch(error => {
console.log(error);
});
} ```