personal_website/controllers/cashTransactionController.js
2023-09-25 20:27:40 +02:00

41 lines
961 B
JavaScript

var cashTransactionModel = require('../models/cashTransactionModel.js');
module.exports = {
list: function (req, res) {
cashTransactionModel.find()
.then(transactions => {
var 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) {
var transaction = new cashTransactionModel({
raw: req.body.messageBody
});
const trans = await transaction.save()
if(trans){
return res.status(201).json({ message: 'Welcome to the API POST' });
}
else{
return res.status(400).json({message: "something went wrong"});
}
},
delete: function (req, res) {
cashTransactionModel.deleteMany({})
.then(data =>{
res.status(201).json({message:"OK"});
});
},
};