Boss Machine Project: why do we use req.body in the instance update method?

Hi all,

I’ve been working on Boss Machine for a few days now, and just peeked at the solution code. One error I am getting is with the required PUT /api/minions/:minionId route, specifically AssertionError: expected { Object (id, name, ...) } to deeply equal { Object (id, name, ...) }. Upon comparing the solution and my code, I noticed that I seem to be doing things correctly (updating the existing resource) but using the wrong type of argument for the function that does the updating of the resource.

Specifically, we have been provided with the function ‘updateInstanceInDatabase(modelType, instance)’ to help us update the resource. I seem to be correctly using ‘minions’ as the first argument, since it is just referring to the type of resource to be modifying, and I used the relevant minion to update for the ‘instance’ argument, since the instance is presumably just referring to the minion (instance of a minion) that we want to update. Here is my code:

//PUT to update a single minion by id
minionsRouter.put('/:minionId', (req, res, next) => {
    const relevantID = req.params.minionId;
    const minionToUpdate = getFromDatabaseById('minions', relevantID);
    if (minionToUpdate) {
        updateInstanceInDatabase('minions', minionToUpdate);
        const updatedMinion = getFromDatabaseById('minions', relevantID);
      } else {

However, instead of using the minion instance as the second parameter for ‘updateInstanceInDatabase’, the solution code uses ‘req.body’ as the second argument. I don’t understand why this is the case, since the parameter for ‘updateInstanceInDatabase’ in the ‘db.js’ file we are given is said to be ‘instance’. I don’t understand what information req.body gives that is necessary for the function to execute over the instance of minion. In fact, in the ‘updateInstanceInDatabase’ function, ‘’ is used, and the ‘id’ property is held by an instance of minion (it is one of the attributes that createMinion returns when a new minion is created). Again, my question is: why are we using req.body instead of instance as the second argument?

Here is the relevant part of the solution code:

minionsRouter.put('/:minionId', (req, res, next) => {
  let updatedMinionInstance = updateInstanceInDatabase('minions', req.body);

A similar question was posed in this post, but the req.body part of it was not answered. Also, I want to note that I have yet to DRY the code, and include the minionsRouter.param block. I suspect my confusion might have something to do with this. I just wanted to get the non-DRYed version correct to understand as much of the material as possible.

Thanks in advance!

Boss Machine Project Link: