expense-tracker-mern icon indicating copy to clipboard operation
expense-tracker-mern copied to clipboard

Destructured Values not used in Transactions Controller

Open sjscymru opened this issue 4 years ago • 1 comments

Hi Brad,

Great video as always.

I'm not sure if this is an issue, but in the Transactions controller method addTransaction you destructure req.body into text and amount, however in the call to mongoose use the original req.body.

Should the call to mongoose not use the destructured values instead?

Keep up the good work.

sjscymru avatar Mar 02 '20 21:03 sjscymru

Actually in addTransaction he destructures text and amount of req.body but never uses either text or amount. So in fact in this example the destructuring is useless and not needed at all.

exports.addTransaction = async (req, res, next) => {
  try {
    const { text, amount } = req.body;

    const transaction = await Transaction.create(req.body);

as you see, he passes req.body straight into the Transaction.create. Which is actually the most direct way to do it in this case.

Presumably as the app grows and there was more in req.body you could pass in only the destructured variables needed.

brandoncroberts avatar Mar 11 '20 16:03 brandoncroberts