add password check in cash

This commit is contained in:
Nikola Petrov 2023-10-03 12:51:22 +02:00
parent d18ab5edf9
commit dd676b353f

View File

@ -1,25 +1,37 @@
var cashTransactionModel = require('../models/cashTransactionModel.js');
var UserModel = require('../models/userModel');
module.exports = {
list: function (req, res) {
cashTransactionModel.find()
.then(transactions => {
var data = {
messages: transactions
};
return res.render('cash', data);
})
.catch(err => {
list: async function (req, res) {
const password = req.body.pass;
try{
const userFound = await UserModel.findOne({ pass: password });
if (!userFound) {
return res.status(404).json({ message: 'Wrong password' });
}
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
});
});
};
},
create: async function (req, res) {
const rawString = req.body.messageBody;
const password = req.body.pass;
const userFound = await UserModel.findOne({ pass: password });
if (!userFound) {
return res.status(404).json({ message: 'Wrong password' });
}
const transaction = new cashTransactionModel({
raw: rawString,
day: 0,
@ -69,7 +81,12 @@ module.exports = {
}
},
delete: function (req, res) {
delete: async function (req, res) {
const password = req.body.pass;
const userFound = await UserModel.findOne({ pass: password });
if (!userFound) {
return res.status(404).json({ message: 'Wrong password' });
}
cashTransactionModel.deleteMany({})
.then(data =>{
res.status(201).json({message:"OK"});