cambios del 24 de abril
This commit is contained in:
@@ -19,4 +19,44 @@ router.get("/compras", checkAuth, async (req, res) => {
|
||||
)
|
||||
});
|
||||
|
||||
|
||||
router.post("/compra", checkAuth, async (req, res) => {
|
||||
const { fecha, detalle, valor, metodopago, categoria } = req.body;
|
||||
const newCompra = new Compra({
|
||||
fecha,
|
||||
detalle,
|
||||
valor,
|
||||
metodopago,
|
||||
categoria,
|
||||
});
|
||||
|
||||
console.log(newCompra)
|
||||
newCompra.user = req.userData._id;
|
||||
await newCompra.save();
|
||||
|
||||
res.json({
|
||||
status:"OK"
|
||||
})
|
||||
|
||||
|
||||
});
|
||||
|
||||
router.delete("/compra", checkAuth, async (req, res) => {
|
||||
|
||||
try{
|
||||
const userId = req.userData._id;
|
||||
const id = req.query.id;
|
||||
|
||||
const resultado = await Compra.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;
|
||||
Reference in New Issue
Block a user