diff --git a/controllers/cashTransactionController.js b/controllers/cashTransactionController.js index c7c3984..5ae64bc 100644 --- a/controllers/cashTransactionController.js +++ b/controllers/cashTransactionController.js @@ -3,7 +3,20 @@ module.exports = { list: async function (req, res) { try { - const transactions = await cashTransactionModel.find({}, { _id: 0, __v: 0 }); + var transactions; + const date = req.body.date; + + if (date) { + const splitDate = date.split('-'); + var year = splitDate[0]; + var month = splitDate[1]; + year = parseInt(year); + month = parseInt(month); + transactions = await cashTransactionModel.find({ year, month }, { _id: 0, __v: 0 }); + } else { + transactions = await cashTransactionModel.find({}, { _id: 0, __v: 0 }); + } + return res.json(transactions); } catch (err) { return res.status(500).json({ diff --git a/views/cash.hbs b/views/cash.hbs index 2250785..7059353 100644 --- a/views/cash.hbs +++ b/views/cash.hbs @@ -9,6 +9,7 @@