DylanNeil / Simule

An app that allows users to post and search for events.
0 stars 0 forks source link

Added working delete function to ./server/server.js #47

Closed DylanNeil closed 4 years ago

DylanNeil commented 4 years ago

Created working delete function in ./server/server.js

DylanNeil commented 4 years ago

So, I first tried events.splice(i,1); When I checked this in the debugger, i was the correct integer. But It didn't work when I actually tried deleting. I didn't think using [i] would work, but for some reason it did. I'll try again - maybe I was missing something.

On Wed, Sep 23, 2020 at 10:46 AM Kevin Fawcett notifications@github.com wrote:

@fawcilize requested changes on this pull request.

In .vscode/launch.json https://github.com/DylanNeil/ReactProject/pull/47#discussion_r493651164:

@@ -0,0 +1,17 @@ +{

Typically you don't commit editor-specific environment files. Not everyone on a team could be using vscode. To fix this, you could add .vscode to the .gitignore file

In server/server.js https://github.com/DylanNeil/ReactProject/pull/47#discussion_r493652145:

res.status(201).send({ eventObject }); });

app.delete('/events/:id',(req, res) => { const requestId = events.find((event) => event.id === req.params.id);

  • res.status(202).send(requestId);
  • return;
  • for(let i=0; i<=events.length -1; i += 1){
  • const eventsID = events[i].id;
  • const currentID = req.params.id;
  • const index = events[i];
  • if(eventsID == currentID){
  • events.splice([i],1);

The first argument to splice should be an index (integer), but you are providing an array

In server/server.js https://github.com/DylanNeil/ReactProject/pull/47#discussion_r493652725:

res.status(201).send({ eventObject }); });

app.delete('/events/:id',(req, res) => { const requestId = events.find((event) => event.id === req.params.id);

  • res.status(202).send(requestId);
  • return;
  • for(let i=0; i<=events.length -1; i += 1){

It's common practice to return a 404 status code (Not found) when the event is not in the list.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/DylanNeil/ReactProject/pull/47#pullrequestreview-494738206, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACUK5EICUVVR57W3GLVSVH3SHIC25ANCNFSM4RXEA56A .