Format
This commit is contained in:
@@ -2,20 +2,18 @@ var cashTransactionModel = require('../models/cashTransactionModel.js');
|
||||
module.exports = {
|
||||
|
||||
list: async function (req, res) {
|
||||
|
||||
try{
|
||||
|
||||
try {
|
||||
const transactions = await cashTransactionModel.find()
|
||||
const data = {
|
||||
messages: transactions
|
||||
};
|
||||
return res.render('cash', data);
|
||||
}catch (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting transactions.',
|
||||
error: err
|
||||
});
|
||||
};
|
||||
} catch (err) {
|
||||
return res.status(500).json({
|
||||
message: 'Error when getting transactions.',
|
||||
error: err
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
create: async function (req, res) {
|
||||
@@ -35,20 +33,20 @@ 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;
|
||||
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;
|
||||
|
||||
if(transaction.type != 0){
|
||||
if (transaction.type != 0) {
|
||||
const amountMatch = rawString.match(amountPattern);
|
||||
if (amountMatch){
|
||||
if (amountMatch) {
|
||||
const amount = amountMatch[0].replace('.', '').replace(',', '.');
|
||||
transaction.amount = parseFloat( amount);
|
||||
}
|
||||
transaction.amount = parseFloat(amount);
|
||||
}
|
||||
|
||||
const companyMatch1 = rawString.match(companyPattern1);
|
||||
if (companyMatch1) transaction.company = companyMatch1[0];
|
||||
@@ -62,18 +60,18 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
const trans = await transaction.save()
|
||||
if(trans){
|
||||
if (trans) {
|
||||
return res.status(201).json(trans);
|
||||
}
|
||||
else{
|
||||
return res.status(400).json({message: "something went wrong"});
|
||||
else {
|
||||
return res.status(400).json({ message: "something went wrong" });
|
||||
}
|
||||
},
|
||||
|
||||
delete: async function (req, res) {
|
||||
cashTransactionModel.deleteMany({})
|
||||
.then(data =>{
|
||||
res.status(201).json({message:"OK"});
|
||||
});
|
||||
.then(data => {
|
||||
res.status(201).json({ message: "OK" });
|
||||
});
|
||||
},
|
||||
};
|
@@ -16,8 +16,6 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
create: async function (req, res) {
|
||||
var gameCode = req.body.code;
|
||||
const userFound = req.user;
|
||||
|
Reference in New Issue
Block a user