Esqueleto presupuesto

This commit is contained in:
2021-05-10 23:34:58 -05:00
parent a05bc18d5a
commit e3abbfd0dc
17 changed files with 677 additions and 29 deletions

73
routes/ingresos.js Normal file
View File

@@ -0,0 +1,73 @@
const router = require("express").Router();
const Ingreso = require("../models/ingresos");
const { checkAuth } = require("../middlewares/authentication");
router.get("/ingreso", checkAuth, async (req, res) => {
var Ingresos;
Ingresos = await Ingreso.find({ user: req.userData._id }).sort({
fecha: "desc",
});
return res.send(
{
status:"ok",
data:Ingresos
}
)
});
router.post("/ingreso", checkAuth, async (req, res) => {
const { fecha, detalle, valor} = req.body;
const newIngreso = new Ingreso({
fecha,
detalle,
valor
});
console.log(newIngreso)
newIngreso.user = req.userData._id;
await newIngreso.save();
res.json({
status:"OK"
})
});
router.put("/ingreso", checkAuth, async (req, res) => {
const { _id, fecha, detalle, valor } = req.body;
const Ingreso_edit = await Ingreso.findOne({ _id: _id });
await Ingreso_edit.updateOne({ fecha, detalle, valor});
res.json({
status:"OK"
})
});
router.delete("/ingreso", checkAuth, async (req, res) => {
try{
const userId = req.userData._id;
const id = req.query.id;
const resultado = await Ingreso.deleteOne({user:userId,_id:id});
return res.json({status:"ok",data: resultado})
}
catch(error){
console.log(error);
return res.status(500).json({status:"fail",error:error})
}
});
module.exports = router;