Boss Machine solution code clarity

Hey all - I’m looking over the solution code to the Boss Machine Cumulative Project and had a few clarifying questions I was hoping someone could answer. Here goes:

Note: I have not DRY’d this code yet. After examining the DRY’d solution, I went back and rewrote it before DRYing so I could understand the code-writing process. Also, I have called the js file where getFromDatabase() and updateInstanceInDatabase() are located using const database = require('./db')

In nearly every route, there is a bit of request logic I don’t understand: It is the req.minion = minion portion of:

app.put('/api/minions/:minionId', (req, res, next) => {
  const minion = database.getFromDatabaseById('minions', req.params.minionId);
  if (minion) {
    req.minion = minion;
    const updatedMinionInstance = database.updateInstanceInDatabase('minions', req.body);
    res.send(updatedMinionInstance);
  } else {
    res.status(404).send();
  }
});

If i’m understanding correction, minion is the object that is pulled using the arguments ‘minion’ and the id specified in the params of the URL. So then we say, if all of that is valid, then… and then I get confused.

Does req.minion mean we now are using the object called using the above function/arguments as the request object? And then, what’s the point of setting it equal to minion again? Is this just sort of converting the function object into our request object?

Then going further, why is req.body being used as the argument in updateInstanceInDatabase()? I realize that’s what we’d typically use, but the req.minion thing threw me off.

Any help is greatly appreciated! Thank you!