Middleware - Review Exercise Issue

Hello there!

I am facing a problem with this exercise, at step 3.

Exercise Link

After transferring the code snippet to an app.use middleware, adding cardIndex to the request object and invoking next, I get a syntax error informing me that on line 78 cardId is not defined.
The code below saws the app.use middleware that I have written:

app.use('/cards/:cardId', (req, res, next) => {
  const cardId = Number(req.params.cardId);
  const cardIndex = cards.findIndex(card => card.id === cardId);
  if (cardIndex === -1) {
    return res.status(404).send('Card not found');
  }
  req.cardIndex = cardIndex;
  next();
});

the code on line 78 is from a put request:

app.put('/cards/:cardId', (req, res, next) => {
  const newCard = req.body;
  const validSuits = ['Clubs', 'Diamonds', 'Hearts', 'Spades'];
  const validRanks = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'Jack', 'Queen', 'King', 'Ace'];
  if (validSuits.indexOf(newCard.suit) === -1 || validRanks.indexOf(newCard.rank) === -1) {
    return res.status(400).send('Invalid card!');
  }
  if (!newCard.id || newCard.id !== cardId) {
    newCard.id = cardId; //<------ THE ERROR
  }
  cards[req.cardIndex] = newCard;
  res.send(newCard);
});

Is there something that I am missing?
Do I need to include anything to next?

Thanks in advance!