Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Destructured Values not used in Transactions Controller #3

Open
sjscymru opened this issue Mar 2, 2020 · 1 comment
Open

Destructured Values not used in Transactions Controller #3

sjscymru opened this issue Mar 2, 2020 · 1 comment

Comments

@sjscymru
Copy link

sjscymru commented Mar 2, 2020

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 sjscymru changed the title Destructured Values in Transactions Controller Destructured Values not used in Transactions Controller Mar 2, 2020
@brandoncroberts
Copy link

brandoncroberts commented Mar 11, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants