nss-day-cohort-46 / How-to-Ask-for-Help

0 stars 0 forks source link

[QUICK ISSUE] #226

Closed KaitlinJKelley closed 3 years ago

KaitlinJKelley commented 3 years ago

Name: Kaitlin

Breakout Room:

REQUIRED Question or issue:

Just want to make sure this code is considered acceptable practice. Instead of using a PUT request to change paths tables when a user edits their route, I delete and recreate the route and paths tables for that route.

REQUIRED Check all that apply:

Code Snippet

PathsProvider2 is the component that create a set of paths tables

    const updateRoute = routeObj => {
        return fetch(`http://localhost:8088/routes/${routeObj.id}`, {
            method: "DELETE"
        })
        .then(() => addNewRoute({
            "name": routeObj.name,
            "origin": routeObj.origin,
            "destination": routeObj.destination,
            "userId": routeObj.userId
        }))
    }
    const addNewRoute = routeObj => {
        return fetch(`http://localhost:8088/routes`, {
            method: "POST",
            headers: {
                "Content-Type": "application/json"
            },
            body: JSON.stringify(routeObj)
        })
        .then(res => res.json())
        .then(setNewRoute)
        .then(getRoutes)
        .then(() => <PathsProvider2 />)
    }
KaitlinJKelley commented 3 years ago

Sage thinks the code itself is fine, but to meet technical CRUD functionality I do need to add another edit field because this refactor removed my only PUT request