<commit_before>const expensesRouter = require('express').Router();
const Expense = require('../../db/models/expense.js');
const Transaction = require('../../db/models/transaction.js');

expensesRouter.post('/', (req, res) => {
  let newTransactions = req.body.transactions;

  const newExpense = {
    userId: req.user._id,
    planId: req.body.planId,
    description: req.body.description,
    amount: req.body.amount,
    transactions: []
  };

  Expense.create(newExpense).then((expense) => {
    for (let i = 0; i < transactions.length; i++) {
      transactions[i].expenseId = expense._id;
    }

    Transaction.create(newTransactions).then((transactions) => {
      for (let i = 0; i < transactions.length; i++) {
        expense.transactions.push(transactions[i]._id);
      }
      expense.save().then(() => {
        console.log('expense', expense);
        res.status(201).json(expense);
      });
    }).catch(err => res.status(500).json({'Server error': err}));
  });
});


expensesRouter.get('/:planId', (req, res) => {
  console.log('get planId for expenses', req.params.planId);
  Expense.find({planId: req.params.planId}).then((expenses) => {
    res.status(200).json(expenses);
  }).catch(err => res.status(500).json({'Server error': err}));
});



module.exports = expensesRouter;<commit_msg>Changed wording of transactions to newTransactions<commit_after>const expensesRouter = require('express').Router();
const Expense = require('../../db/models/expense.js');
const Transaction = require('../../db/models/transaction.js');

expensesRouter.post('/', (req, res) => {
  let newTransactions = req.body.transactions;

  const newExpense = {
    userId: req.user._id,
    planId: req.body.planId,
    description: req.body.description,
    amount: req.body.amount,
    transactions: []
  };

  Expense.create(newExpense).then((expense) => {
    for (let i = 0; i < newTransactions.length; i++) {
      newTransactions[i].expenseId = expense._id;
    }

    Transaction.create(newTransactions).then((transactions) => {
      for (let i = 0; i < transactions.length; i++) {
        expense.transactions.push(transactions[i]._id);
      }
      expense.save().then(() => {
        console.log('expense', expense);
        res.status(201).json(expense);
      });
    }).catch(err => res.status(500).json({'Server error': err}));
  });
});


expensesRouter.get('/:planId', (req, res) => {
  console.log('get planId for expenses', req.params.planId);
  Expense.find({planId: req.params.planId}).then((expenses) => {
    let ledger = {
      expenses: expenses,
      transactions: {}
    };
    expenses.forEach((expense) => {
      
    });

    res.status(200).json(expenses);
  }).catch(err => res.status(500).json({'Server error': err}));
});



module.exports = expensesRouter;
{'fraction_non_alphanumeric': 0.19148174659985684, 'fraction_numerical': 0.010021474588403722, 'mean_word_length': 3.408517350157729, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6175325', 'n_tokens_mistral': 919, 'n_tokens_neox': 895, 'n_words': 150}