forked from dkwon1223/fitlit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functionality for the user to add in hydration data.
- Loading branch information
1 parent
2698725
commit 8eb10df
Showing
4 changed files
with
218 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,38 @@ | ||
function fetchUserData(usersData) { | ||
return fetch("https://fitlit-api.herokuapp.com/api/v1/users") | ||
return fetch("http://localhost:3001/api/v1/users") | ||
.then((response) => response.json()) | ||
.then((data) => (usersData = data)); | ||
} | ||
function fetchHydrationData(hydration) { | ||
return fetch("https://fitlit-api.herokuapp.com/api/v1/hydration") | ||
return fetch("http://localhost:3001/api/v1/hydration") | ||
.then((repsonse) => repsonse.json()) | ||
.then((data) => (hydration = data)); | ||
} | ||
|
||
function fetchSleepData(sleep) { | ||
return fetch("https://fitlit-api.herokuapp.com/api/v1/sleep") | ||
return fetch("http://localhost:3001/api/v1/sleep") | ||
.then((repsonse) => repsonse.json()) | ||
.then((data) => (sleep = data)); | ||
} | ||
|
||
export { fetchHydrationData, fetchUserData, fetchSleepData}; | ||
function postHydrationData(date, numOunces, userID) { | ||
fetch("http://localhost:3001/api/v1/hydration", { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
date, | ||
numOunces, | ||
userID | ||
}), | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
.then(response => { | ||
if(!response.ok) { | ||
throw new Error("There was an issue adding your hydration details. Please try again later.") | ||
} | ||
return response.json(); | ||
}) | ||
.then(data => console.log(data)) | ||
.catch(error => popUpError.innerText = error.message) | ||
} | ||
|
||
export { fetchHydrationData, fetchUserData, fetchSleepData, postHydrationData }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters