Need help: Issue Tracker!

Hi every one!

I can’t get right the following point:

  • You can send a PUT request to /api/issues/{projectname} with an _id and one or more fields to update. On success, the updated_on field should be updated, and returned should be { result: 'successfully updated', '_id': _id }.

Can any one help me? Thanks a lot!

Your project link(s)


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36 Edg/91.0.864.54

Challenge: Issue Tracker

Link to the challenge:

this is a very vague description. What exactly you fail to do?
Obviously you want to handle a PUT request which includes an _id and undefined number of additional fields. You could prolly use a find and update mongoose query, providing the _id to look for and any additional parameters as arguments to be updated. If the query succeed without error and return a valid document, you should send the specified info object { result: 'successfully updated', '_id': _id }

Hi @Sylvant !

The point is that I really don’t know why my code fails on the test. I have done numerous tests, but the result is the same.

Here is the probably wrong code:

.put(async function (req, res) {
      let project = req.params.project;
      const Issue = mongoose.model(project, issueSchema);

      console.log('IN: ',req.body)

      if (!req.body._id) {
        console.log('OUT: ',{ error: 'missing _id' })
        return res.status(200).json({ error: 'missing _id' });

      if (
        !req.body.issue_title &&
        !req.body.issue_text &&
        !req.body.created_by &&
        !req.body.assigned_to &&
        !req.body.status_text &&
      ) {
        console.log('OUT: ',{ error: 'no update field(s) sent', '_id': req.body._id })
        return res.status(200).json({ error: 'no update field(s) sent', '_id': req.body._id });

      await Issue.findById(req.body._id, function (err, doc) {
        if (err || !doc) {
          console.log('OUT: ',{ error: 'could not update', '_id': req.body._id })
          res.status(200).json({ error: 'could not update', '_id': req.body._id })
        } else {
          Issue.findByIdAndUpdate(req.body._id, {
            issue_title: req.body.issue_title,
            issue_text: req.body.issue_text,
            created_by: req.body.created_by,
            assigned_to: req.body.assigned_to,
            status_text: req.body.status_text,
            updated_on: new Date(),
            open: === 'false' ? false : true
          }, { new: true, omitUndefined: true }, function (err, doc) {
            console.log('OUT: ',doc)
            if (err) res.status(500).json({ message: 'Internal server error' });
            res.status(200).json({ result: 'successfully updated', '_id': req.body._id });

When all else fails, look at the source for the tests on github.

Your PUT route appears to mostly work, but the test still fails. Instead of believing your PUT route, the fCC tests also GET the issue by id to verify the response from PUT. Your GET route does not return issues when requested by id (it returns all issues, not the one issue), so your GET route is causing your PUT route test to fail.

So, implement GET by id (that would be one of the one filter GET requests…).

1 Like

I have no words to thank you! You saved my day!

Thank you so much!

Hi again @jeremy.a.gray !

Can you explain to me where exactly can I get the access to the test source? :sweat_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.