Quality Assurance Projects - Issue Tracker

PUT Request Error: Issue Tracker Update Problem

Describe your issue in detail here.

When I tried to update an issue in issue tracker project using a PUT request, I got an error message that said, “expected undefined to be an object.”
I double-checked everything and made sure that the update worked perfectly in the databases. I even used console.log to confirm that the data was updated correctly. However, the test still didn’t pass, and I’m not sure why.

.put(async function(req, res) {
      try {
        const project = req.params.project;
        const { _id, ...updateFields } = req.body;

        if (!_id) {
          return res.json({ error: 'missing _id' });
        }

        if (Object.keys(updateFields).length === 0) {
          return res.json({ error: 'no update field(s) sent', _id });
        }

        const projectData = await ProjectModel.findOne({ name: project }).exec();

        if (!projectData) {
          return res.json({ error: 'Project not found', _id });
        }

        const issue = projectData.issues.id(_id);

        if (!issue) {
          return res.json({ error: 'could not update', _id });
        }


        for (const field in updateFields) {
          issue[field] = updateFields[field];
        }

        issue.updated_on = new Date();


        await projectData.save();

        return res.json({ result: 'successfully updated', '_id': req.body._id })
      } catch (err) {
        res.json({ error: 'could not update', _id });
      }
    })

For this test:

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 }.

Getting error :
[Error: expected undefined to be an object]

My project link(s)

solution: boilerplate-project-issuetracker (1) - Replit

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge: Quality Assurance Projects - Issue Tracker

Link to the challenge:

It is the GET request after the PUT that is failing.

Request URL: https://boilerplate-project-issuetracker-1.codebrakerk.repl.co/api/issues/fcc-project?_id=65171be0969228532f7fed98
Response: []

Your DELETE code seems to be throwing, as it is the catch response code that is being sent.

1 Like

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