Unlimited WordPress themes, graphics, videos & courses! Unlimited asset downloads! From $16.50/m
Web app with node express and vue 400x277
  • Overview
  • Transcript

5.5 Deleting Addresses

In the previous lesson, we finally got our portfolio working. We are displaying our addresses. We are able to add addresses. The only issue really is it appears that there is some throttling going on. And in fact, I did do some checking and it doesn't like the amount of requests that are coming from the same IP. I tried putting in a delay to see if that helped, and eventually, a delay would help, but at that point, it just doesn't become feasible. I mean because if you have a portfolio of ten currencies, then there's really no reason to put a delay there, otherwise you'll be sitting there for a long time. So we're not going to worry too much about that, we're just going to finish what we started and add the ability to delete any one of those records. So let's go to our client API because we stubbed out this method, but we do need to finish it. So we will do essentially the same thing except that we are going to incorporate the ID of the record that we want to delete. So we are going to include that with this URL so we will have portfolio/ and then we will have the record_id. I think we used just a normal id, I don't think we Had an underscore in front of it. And we can very easily look at that, because we're going to have to open this file anyway. So let's open up our portfolio file in our server side. And let's see. Yes, we have just a normal, regular ID property. So, that's okay. We are going to submit that request there. And then we need to change this to delete. And I don't think we even need to pass in the record itself. Because all we need is the record ID. So we are going to make a delete request to our URL. We are including the authorization token so that we know who we are. And that's it. So let's go to our service side. And let's finish this. So, let's just copy what we have for our post request. And let's change this to delete, we do need a rout parameter which we'll just call recordID, and we will, first of we need that user, but let's also get the recordID from the params. So that gives us that value. So now what we want to do is retrieve the record from our portfolio with that id. So there is a variety of different ways that we could do this. And we will do something similar to what we did on the client side as far as using splice and things like that. But first we need to get the index. So what we are going to do is say user.portfolio. And then we are going to use the findIndex method. And we want to work with an individual record. And we want that record that has an ID equal to the record ID. So it will just return that. Hopefully, we will have a valid index. So if index is greater than -1, well then we know we have found what we need to remove. And so we will just say user.portfolio, and then we will splice at the given index and we just want 1 there. Now if index is negative one, I'm not sure what we want to do there. But we'll just leave this code as is. And we will see if it actually works. So let's go to the browser. Let's refresh our page here. And let's try to delete stipend since that is the one that's giving us the most trouble. Are we sure that we want to delete this record? Yes, okay, so that one away. That's at least a good sign, let's do a refresh. And sure enough we have just a single record. Let's go ahead and delete that one from our portfolio. So that we have a completely clean slate. And there we go. So we now have the ability to add an address to our portfolio. We now have the ability to delete an address from our portfolio. So now we get to focus on security. And there are two things about the security of our application. We need security on the client side and security on the server. And we will talk about that in the next lesson

Back to the top