0

I have a PUT request that I'm trying to have hit the backend, but for some reason, it never reaches it. What's odd is the if(req.body.bidderId){} hits no problem, but not the if(req.body.watchingGroup){}

The watching angular service uses identical code to the bidderId so I don't know what's different between the two where only one would reach the endpoint? Whats wrong with the addToWatchList call? I did testing and both console.log statements in code block return the correct value. So the data is ready to be passes, but is never received.

console.log("MADE IT TO LISTINGS BACKEND"); never outputs for watchingGroup scenario

watching.service.ts

addToWatchList(id: string, watchingGroup: string[]) {
    const watching: Watching = {
      id: id,
      watchingGroup: watchingGroup
    };
    console.log("Here are the values being passed to backend");
    console.log(watching.id);
    console.log(watching.watchingGroup);
    console.log(watching);
    return this.http.put(`http://localhost:3000/api/listings/${watching.id}`, watching,
    );
  }

app.js

app.put("/api/listings/:id", (req, res) => {
  console.log("MADE IT TO LISTINGS BACKEND");

  if (req.body.biddingGroup) {
    console.log("bidding has been received");

    Post.findByIdAndUpdate(
      { _id: req.params.id },
      {
        currentBid: req.body.currentBid,
        lastBidTimeStamp: Date.now(),
        bidderId: req.body.bidderId,
        auctionEndDateTime: req.body.auctionEndDateTime,
        biddingGroup: req.body.biddingGroup,
        lastBidTimeStamp: req.body.lastBidTimeStamp
      },
      function(err, docs) {
        if (err) res.json(err);
        else {
          console.log(docs);
        }
      }
    );
  }
  if (req.body.watchingGroup) {
    console.log("watching has been received");

    Post.findByIdAndUpdate(
      { _id: req.params.id },
      {
        watchingGroup: req.body.watchingGroup
      },
      function(err, docs) {
        if (err) res.json(err);
        else {
          console.log(docs);
        }
      }
    );
  }
});

addToWatchList

 addToWatchList(
    auctionId: string,
    watchingGroup: string[]
  ) {
    this.watchItStatus = true;
    this.userId = localStorage.getItem("userId: ");

    var unique = watchingGroup.filter(function(elem, index, self) {
      return index === self.indexOf(elem);
    });
    this.uniqueResult = unique;
    watchingGroup.push(this.userId);
    this.watchListService.addToWatchList(auctionId, this.uniqueResult);
  }
6
  • Can you share the snippet from which addToWatchList is being called. Commented Dec 4, 2019 at 17:56
  • The values are definitely being passed from the addToWatchList call. I added some console logs in code above and screenshot to demonstrate Commented Dec 4, 2019 at 18:05
  • I don't see any errors in that code that's why I just wanted see addToWatchList is being called. Commented Dec 4, 2019 at 18:09
  • I added addToWatchList() to my code above Commented Dec 4, 2019 at 18:32
  • This is not what I've asked. I need snippet from where addToWatchList is being called. Commented Dec 4, 2019 at 18:37

1 Answer 1

1

As i suspected you're not subscribing to it. It's weird but you need to subscribe to it.

this.watchListService.addToWatchList(auctionId, this.uniqueResult).subscribe(
  (res) => {
    // Handle success response
    console.log("SUCCESS");
  },
  (err) => {
    // Handle error response
    console.log("ERROR");
  }
);
Sign up to request clarification or add additional context in comments.

1 Comment

Cool.. n that's y i was obsessed with that part. I've been there too, Spent whole night debugging it. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.