WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

Tag associated to Apartment/Receiving an error message in Postman and terminal #45

Closed isaac8069 closed 2 years ago

isaac8069 commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

MERN

What's the problem you're trying to solve?

Patch route to add tag to apartment. Both tag and apartment have already been created. I find the apartmentId, then I push a tag into an apartment:tagRef array. I also don't understand how you choose which tag? I understand the apartment is found using apartmentId but I don't understand based on my code how I choose which tag.

Post any code you think might be relevant (one fenced block per file)

// Find apartment and push a tag in the tag array within apartment
router.post('/tags/:apartmentId', jsonParser, (req, res, next) => {
  Apartment.findById(req.params.apartmentId)
      .then(apartment => {
          // add (push) the new tag into the apartment's tags array
          apartment.tags.push(req.body.tag)
          // then I'll need to save the apartment
          return apartment.save()
      })
      // after that we can return the apartment and send the status with some JSON
      .then(apartment => {
          res.status(201).json({ apartment: apartment.toObject() })
      })
      .catch(next)
})

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

"type": "entity.parse.failed"

What is your best guess as to the source of the problem?

I'm not sure i add NPM Body-Parser and tried to see if that would help

What things have you already tried to solve the problem?

tkolsrud commented 2 years ago

The tags have an id too right? So apartmentId is coming from the url bc it's based on user input. The tag id would be used to include the tag in the apartment info when the page renders*

isaac8069 commented 2 years ago

I understand the tagId being used to choose which tag, but I am not following on if that is something I need to add to this code or if you are just explaining the logic of the code. Also, the error message: "type": "entity.parse.failed". Is this saying it failed to pass a different type to another type?

tkolsrud commented 2 years ago

What do you mean when you say "which tag"? Like if you're trying to access a specific tag from the apartment's array? (Also, would you mind posting a screenshot of the entire type error)

isaac8069 commented 2 years ago

Example

Apartments: Apt1, Apt2, Apt3 Apt1Id = 123 Apt2Id = 345 Apt3Id = 567 Tags: apple, orange, lemon Association Apt1Id = lemon Apt2Id = lemon, apple Apt3Id = orange Based on the code block I don't see where tagId is coming into play. So how can I determine the tag I want to associate to an apt? Hopefully that will help with the question I am asking.

tkolsrud commented 2 years ago

It looks like it's using req.body.tag -- so there's a form where a tag is being entered/created?

isaac8069 commented 2 years ago

Resolved