expense-tracker-mern
expense-tracker-mern copied to clipboard
Destructured Values not used in Transactions Controller
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.
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.