This commit is contained in:
Nikola Petrov
2023-10-09 18:56:29 +02:00
parent d12d0d10f8
commit 7606654e30
2 changed files with 19 additions and 13 deletions

View File

@@ -1,4 +1,6 @@
var cashTransactionModel = require('../models/cashTransactionModel.js');
const types = ['ZAVRNITEV POS NAKUP', 'POS NAKUP', 'BA DVIG', 'priliv', 'SDD', 'SPLET/TEL NAKUP', 'PREDAVTORIZACIJE'];
module.exports = {
list: async function (req, res) {
@@ -17,7 +19,9 @@ module.exports = {
transactions = await cashTransactionModel.find({}, { _id: 0, __v: 0 });
}
return res.json(transactions);
const data = { transactions: transactions, types: types };
return res.json(data);
} catch (err) {
return res.status(500).json({
message: 'Error when getting transactions.',
@@ -37,7 +41,7 @@ module.exports = {
month: 0,
year: 0,
amount: 0,
type: 0,
type: -1,
company: "",
});
@@ -45,15 +49,14 @@ module.exports = {
const amountPattern = /\d{1,3}(?:[.]\d{3})*(?:[.,]\d{2})(?=\sEUR)/;
const companyPattern1 = /(?<=(UR,|\sod)\s).*?(?=\s(na\s|za\s|Inf))/;
if (rawString.includes("ZAVRNITEV POS NAKUP")) transaction.type = 2;
else if (rawString.includes("POS NAKUP")) transaction.type = 1;
else if (rawString.includes("BA DVIG")) transaction.type = 3;
else if (rawString.includes("priliv")) transaction.type = 4;
else if (rawString.includes("SDD")) transaction.type = 5;
else if (rawString.includes("SPLET/TEL NAKUP")) transaction.type = 6;
else if (rawString.includes("PREDAVTORIZACIJE")) transaction.type = 7;
for (var i = 0; i < types.length; i++) {
if (rawString.includes(types[i])) {
transaction.type = i;
break;
}
}
if (transaction.type != 0) {
if (transaction.type != -1) {
const amountMatch = rawString.match(amountPattern);
if (amountMatch) {
const amount = amountMatch[0].replace('.', '').replace(',', '.');
@@ -81,7 +84,7 @@ module.exports = {
},
delete: async function (req, res) {
cashTransactionModel.deleteMany({ type: 0 })
cashTransactionModel.deleteMany({ type: -1 })
.then(data => {
res.status(201).json({ message: "OK" });
});