Move cash transaction to sql
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { type Request, type Response } from "express";
|
||||
import cashTransactionModel from '../models/cashTransactionModel.js';
|
||||
|
||||
import cashTransactionModel from '../models/cashTransactionModel';
|
||||
|
||||
const types = ['ZAVRNITEV POS NAKUP', 'POS NAKUP', 'BA DVIG', 'priliv', 'SDD', 'SPLET/TEL NAKUP', 'PREDAVTORIZACIJE'];
|
||||
|
||||
@@ -16,9 +17,9 @@ export default {
|
||||
var month = splitDate[1];
|
||||
year = parseInt(year);
|
||||
month = parseInt(month);
|
||||
transactions = await cashTransactionModel.find({ year, month }, { _id: 0, __v: 0, raw: 0 });
|
||||
transactions = await cashTransactionModel.findWithPar(year, month);
|
||||
} else {
|
||||
transactions = await cashTransactionModel.find({}, { _id: 0, __v: 0, raw: 0 });
|
||||
transactions = await cashTransactionModel.find();
|
||||
}
|
||||
|
||||
const data = { transactions: transactions, types: types };
|
||||
@@ -37,15 +38,15 @@ export default {
|
||||
|
||||
if (rawString == "") return res.status(400).json({ message: "empty string" });
|
||||
|
||||
const transaction = new cashTransactionModel({
|
||||
raw: rawString,
|
||||
const transaction = {
|
||||
rawMessage: rawString,
|
||||
day: 0,
|
||||
month: 0,
|
||||
year: 0,
|
||||
amount: 0,
|
||||
type: -1,
|
||||
company: "",
|
||||
});
|
||||
};
|
||||
|
||||
const datePattern = /(0[1-9]|[12][0-9]|3[01])\.(0[1-9]|1[0-2])\.(19|20)\d{2}/;
|
||||
const amountPattern = /\d{1,3}(?:[.]\d{3})*(?:[.,]\d{2})(?=\sEUR)/;
|
||||
@@ -76,7 +77,7 @@ export default {
|
||||
transaction.year = date[2];
|
||||
}
|
||||
}
|
||||
const trans = await transaction.save()
|
||||
const trans = await cashTransactionModel.save(transaction.rawMessage, transaction.day, transaction.month, transaction.year, transaction.amount, transaction.type, transaction.company);
|
||||
if (trans) {
|
||||
return res.status(201).json(trans);
|
||||
}
|
||||
@@ -86,7 +87,7 @@ export default {
|
||||
},
|
||||
|
||||
delete: async function (req: Request, res: Response) {
|
||||
cashTransactionModel.deleteMany({ type: -1 })
|
||||
cashTransactionModel.findOneAndDelete(-1)
|
||||
.then(data => {
|
||||
res.status(201).json({ message: "OK" });
|
||||
});
|
||||
|
Reference in New Issue
Block a user