From aa52a1701b0a1f6b884153215f208f34adb3fa3d Mon Sep 17 00:00:00 2001 From: Jason Date: Fri, 3 Jun 2022 18:06:11 -0500 Subject: [PATCH] working through delete request through api --- js/models.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/js/models.js b/js/models.js index d7da19c..99c2777 100644 --- a/js/models.js +++ b/js/models.js @@ -176,29 +176,40 @@ class User { ); } - /** first method */ - //take a story instance and insert into user favorite array... + /** first method - take a story instance and insert into our array + * of favorites for a partiuclar user + */ - //what information should appear in this array? - //my guess is some story information, information to load story later async insertStoryIntoFavorites(story) { const response = await axios({ url: `${BASE_URL}/users/${currentUser.username}/favorites/${story.storyId}`, method: "POST", - data: { token: `${currentUser.loginToken}` } + data: { token: `${currentUser.loginToken}` } }); - console.log("our response from the api post ...", response); - // currentUser.favorites.push(story); - console.log("what's inside my favorite list... ", currentUser.favorites); + + return currentUser.favorites.push(story); } - /** second method */ + /** second method - take a story instance and remove it from our array of + * favorited articles + */ + + async removedStoryFromFavorites(story) { + const response = await axios({ + url: `${BASE_URL}/users/${currentUser.username}/favorites/${story.storyId}`, + method: "DELETE", + data: { token: `${currentUser.loginToken}` } + }); + + return currentUser.favorites; + + }