diff --git a/controllers/cashTransactionController.js b/controllers/cashTransactionController.js
index 89360a8..c7c3984 100644
--- a/controllers/cashTransactionController.js
+++ b/controllers/cashTransactionController.js
@@ -3,11 +3,8 @@ module.exports = {
list: async function (req, res) {
try {
- const transactions = await cashTransactionModel.find()
- const data = {
- messages: transactions
- };
- return res.render('cash', data);
+ const transactions = await cashTransactionModel.find({}, { _id: 0, __v: 0 });
+ return res.json(transactions);
} catch (err) {
return res.status(500).json({
message: 'Error when getting transactions.',
@@ -19,6 +16,8 @@ module.exports = {
create: async function (req, res) {
const rawString = req.body.messageBody;
+ if (rawString == "") return res.status(400).json({ message: "empty string" });
+
const transaction = new cashTransactionModel({
raw: rawString,
day: 0,
diff --git a/routes/api/cashTransactionRouter.js b/routes/api/cashTransactionRouter.js
index e1778b8..f203d30 100644
--- a/routes/api/cashTransactionRouter.js
+++ b/routes/api/cashTransactionRouter.js
@@ -2,7 +2,7 @@ var express = require('express');
var router = express.Router();
const cashTransaction = require('../../controllers/cashTransactionController.js')
-router.get('/', cashTransaction.list);
+router.post('/list', cashTransaction.list);
router.post('/', cashTransaction.create);
diff --git a/routes/main.js b/routes/main.js
index cd23c79..a6c6bf9 100644
--- a/routes/main.js
+++ b/routes/main.js
@@ -18,6 +18,10 @@ router.get('/list', function (req, res, next) {
res.render('list', { title: 'List' });
});
+router.get('/cash', function (req, res, next) {
+ res.render('cash', { title: 'Cash' });
+});
+
const userRouter = require('./user');
//router.use('/user', userRouter);
diff --git a/views/cash.hbs b/views/cash.hbs
index 00135c2..2c3f3e5 100644
--- a/views/cash.hbs
+++ b/views/cash.hbs
@@ -1,32 +1,39 @@
-
Message:
+
-
-
-
- # |
- Day |
- Month |
- Year |
- Amount |
- Type |
- Company |
- Raw |
-
-
-
+
- {{#each messages}}
-
- {{@index}} |
- {{day}} |
- {{month}} |
- {{year}} |
- {{amount}} EUR |
- {{type}} |
- {{company}} |
- {{raw}} |
-
- {{/each}}
-
-
-
\ No newline at end of file
+
+
+
+
+
+ # |
+ Day |
+ Month |
+ Year |
+ Amount |
+ Type |
+ Company |
+ Raw |
+
+
+
+
+
+
+
\ No newline at end of file