Cannot pass /api/issues/{projectname} test in Issue tracker prokje

Tell us what’s happening:
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 }

Your code so far

.put(function(req, res) {
            let project = req.params.project;
            let {
                _id,
                issue_text,
                issue_title,
                created_by,
                assigned_to,
                status_text,
                open
            } = req.body;
            let updateObj = req.body;

            const collection = myDataBase.collection(project);

            if(!_id) {
                return res.json({ error: 'missing _id' });
            } else if(Object.values(req.body).filter(i => i !== "").length === 1) {
                return res.json({error: 'no update field(s) sent', '_id': _id });
            }else if(!ObjectID.isValid(_id)) {
                return res.json({error: "could not update", "_id": _id});
            } else {
                console.log("PUT body: ", req.body);
                collection.updateOne({_id: ObjectID(_id)}, {
                    $set: {
                        updated_on: new Date().toISOString(),
                        issue_text: issue_text,
                    },
                    $inc: {
                       updated_on: new Date().toISOString() 
                    }

                }, {
     upsert: true
   }, (err, data) => {
                    if(!!err) {
                        return res.json({error: "could not update", "_id": _id});
                    } else if (!!data) {
                        return res.json({  result: 'successfully updated', '_id': _id })
                    }
                })
            }
        })

Your browser information:

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

Challenge: Issue Tracker

Link to the challenge:

You did not pass all updated item to $set

 $set: {
           updated_on: new Date().toISOString(),
           issue_text: issue_text, // this line only update issue_text
           //  You should pass all updated value here
  }

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