Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7 criar transaçao #43

Merged
merged 15 commits into from
Dec 4, 2020
Merged
Prev Previous commit
Next Next commit
Adiciona rota para exclusao de transaçoes
  • Loading branch information
JongaMatos committed Dec 3, 2020
commit 3112a671fcc71ed634c4dde5219517a19594101a
24 changes: 22 additions & 2 deletions api/app/routes/controllers/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ routes.post('/', //Cria transações
});

routes.get('/', //Retorna lista de transações pelo id do usuario (userId).
async (req, res) => {
async (req, res) => {
try {
const list = await Transaction.findAll({ where: { userId: req.body.userId } });

Expand All @@ -47,7 +47,7 @@ routes.get('/', //Retorna lista de transações pelo id do usuario (userId).
console.log("###############################################")

}
})
});
routes.put('/', //Atualiza transação
async (req, res) => {
try {
Expand All @@ -70,6 +70,26 @@ routes.put('/', //Atualiza transação
console.log(err)
console.log("###############################################")
}
});
routes.delete('/',
async (req, res) => { // Deleta uma transação por id.
try {
let transaction = await Transaction.findOne({ where: { id: req.body.id } });
if (transaction) {

Transaction.destroy({ where: { id: req.body.id } })

return res.status(httpStatus.OK).json({ message: "Transação excluida com sucesso" });
} else {
return res.status(404).json({ message: "Transação não encontrada" })
}

} catch (err) {
console.log("###############################################")
console.log(err)
console.log("###############################################")
}

})

export default routes;