Skip to content
Snippets Groups Projects
Commit 140c4c55 authored by meskio's avatar meskio :tent:
Browse files

Block empty purchases

parent 4618bd72
No related branches found
No related tags found
No related merge requests found
...@@ -39,6 +39,11 @@ func (a *api) AddPurchase(num int, w http.ResponseWriter, req *http.Request) { ...@@ -39,6 +39,11 @@ func (a *api) AddPurchase(num int, w http.ResponseWriter, req *http.Request) {
total += product.Price * p.Ammount total += product.Price * p.Ammount
purchase[i].Price = product.Price purchase[i].Price = product.Price
} }
if total == 0 {
log.Printf("Empty purchase (%d)", num)
w.WriteHeader(http.StatusNotAcceptable)
return
}
httpStatus := a.substractMemberBalance(num, total) httpStatus := a.substractMemberBalance(num, total)
if httpStatus != http.StatusOK { if httpStatus != http.StatusOK {
......
...@@ -14,6 +14,8 @@ function ShowTransaction() { ...@@ -14,6 +14,8 @@ function ShowTransaction() {
case "purchase": case "purchase":
show_list = <ShowPurchase purchase={transaction.purchase} />; show_list = <ShowPurchase purchase={transaction.purchase} />;
break; break;
default:
show_list = null;
} }
return ( return (
......
...@@ -93,9 +93,9 @@ class Purchase extends React.Component { ...@@ -93,9 +93,9 @@ class Purchase extends React.Component {
}) })
.catch(error => { .catch(error => {
if (error.name === "not-money") { if (error.name === "not-money") {
this.setState({isLoading: false, error: null, noMoney: true}); this.setState({isLoading: false, noMoney: true});
} else { } else {
this.setState({isLoading: false, error: error}) this.setState({isLoading: false, error: error.message})
} }
}); });
} }
...@@ -106,7 +106,7 @@ class Purchase extends React.Component { ...@@ -106,7 +106,7 @@ class Purchase extends React.Component {
} }
let alert; let alert;
if (this.state.noMoney != null) { if (this.state.noMoney) {
alert = ( alert = (
<Alert variant="warning"> <Alert variant="warning">
No tienes suficiente dinero para realizar esta compra. No tienes suficiente dinero para realizar esta compra.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment