diff --git a/api/order.go b/api/order.go index 64d7564b26808567fe504720d56713e50daef0b5..1c05d46a7258132ac11080c2d8c8c1ad39d300d9 100644 --- a/api/order.go +++ b/api/order.go @@ -34,7 +34,7 @@ type OrderPurchase struct { OrderID uint `json:"order_id"` Order *Order `json:"-"` Price int `json:"price"` - Ammount int `json:"ammount"` + Amount int `json:"amount"` } type OrderGetResponse struct { @@ -65,7 +65,7 @@ func (a *api) deactivateOrders() { for _, order := range orders { total := 0 for _, purchase := range order.Purchases { - total += purchase.Price * purchase.Ammount + total += purchase.Price * purchase.Amount } transaction := Transaction{ @@ -228,7 +228,7 @@ func (a *api) AddOrderPurchase(num int, w http.ResponseWriter, req *http.Request found := false for _, product := range order.Products { if product.Code == p.ProductCode { - total += product.Price * p.Ammount + total += product.Price * p.Amount purchase[i].Price = product.Price found = true break diff --git a/api/order_test.go b/api/order_test.go index b11144a7266f72a8f8a14ad7ca7ac085d4920bc4..034383855538d7acc7d70940b885d7df5043639e 100644 --- a/api/order_test.go +++ b/api/order_test.go @@ -78,7 +78,7 @@ func TestOrderPurchase(t *testing.T) { purchase := []OrderPurchase{ { ProductCode: testProduct.Code, - Ammount: 3, + Amount: 3, OrderID: orders[0].ID, }, } @@ -173,7 +173,7 @@ func TestOrderDeactivation(t *testing.T) { purchase := []OrderPurchase{ { ProductCode: testProduct.Code, - Ammount: 3, + Amount: 3, OrderID: orders[0].ID, }, } @@ -256,7 +256,7 @@ func TestGetOrder(t *testing.T) { purchase := []OrderPurchase{ { ProductCode: testProduct.Code, - Ammount: 3, + Amount: 3, OrderID: orders[0].ID, }, } diff --git a/api/purchase.go b/api/purchase.go index aa4010c8376493fc8383e8147408884681cc0092..235e85e453d242b3298bfdf826d0f656d41e3102 100644 --- a/api/purchase.go +++ b/api/purchase.go @@ -16,7 +16,7 @@ type Purchase struct { ProductCode int `json:"code" gorm:"column:product"` Product Product `json:"product" gorm:"foreignKey:ProductCode;references:Code"` Price int `json:"price"` - Ammount int `json:"ammount"` + Amount int `json:"amount"` } func (a *api) AddPurchase(num int, w http.ResponseWriter, req *http.Request) { @@ -37,7 +37,7 @@ func (a *api) AddPurchase(num int, w http.ResponseWriter, req *http.Request) { return } - total += product.Price * p.Ammount + total += product.Price * p.Amount purchase[i].Price = product.Price } if total == 0 { @@ -63,10 +63,10 @@ func (a *api) AddPurchase(num int, w http.ResponseWriter, req *http.Request) { for _, p := range purchase { err := tx.Model(&Product{}). Where("code = ?", p.ProductCode). - Update("stock", gorm.Expr("stock - ?", p.Ammount)).Error + Update("stock", gorm.Expr("stock - ?", p.Amount)).Error if err != nil { httpStatus = http.StatusInternalServerError - return fmt.Errorf("Can't update product stock %d-%d: %v", p.ProductCode, p.Ammount, err) + return fmt.Errorf("Can't update product stock %d-%d: %v", p.ProductCode, p.Amount, err) } } return nil diff --git a/api/purchase_test.go b/api/purchase_test.go index 92a4a4211a439e6015a429c5714a8a9ecb64fd42..0ba1285d0e39a30dfb68d126d2fe40dad4d58bd3 100644 --- a/api/purchase_test.go +++ b/api/purchase_test.go @@ -14,7 +14,7 @@ func TestPurchaseAddListMine(t *testing.T) { products := []Purchase{ { ProductCode: testProduct.Code, - Ammount: 5, + Amount: 5, }, } resp := tapi.do("POST", "/purchase", products, nil) @@ -30,7 +30,7 @@ func TestPurchaseAddListMine(t *testing.T) { if len(transactions) != 1 { t.Fatal("Wrong number of transactions", len(transactions), transactions) } - if transactions[0].Total != -testProduct.Price*products[0].Ammount { + if transactions[0].Total != -testProduct.Price*products[0].Amount { t.Error("Wrong total:", transactions[0].Total) } if len(transactions[0].Purchase) != 1 { @@ -48,7 +48,7 @@ func TestPurchaseAddListMine(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Error("Can't find the product:", resp.Status) } - if product.Stock != testProduct.Stock-products[0].Ammount { + if product.Stock != testProduct.Stock-products[0].Amount { t.Error("Wrong product stock:", product) } @@ -57,7 +57,7 @@ func TestPurchaseAddListMine(t *testing.T) { if resp.StatusCode != http.StatusOK { t.Error("Can't find the member:", resp.Status) } - if member.Balance != testMember.Balance-(testProduct.Price*products[0].Ammount) { + if member.Balance != testMember.Balance-(testProduct.Price*products[0].Amount) { t.Error("Wrong product balance:", member.Balance) } } diff --git a/api/topup.go b/api/topup.go index e4d9d44bb5c6c97d2635bf25879fea74dcee7719..7db5cb4197532784704021cd915d0de72488cd9b 100644 --- a/api/topup.go +++ b/api/topup.go @@ -21,7 +21,7 @@ func (a *api) AddTopup(adminNum int, w http.ResponseWriter, req *http.Request) { var topup struct { Member int `json:"member"` Comment string `json:"comment"` - Ammount int `json:"ammount"` + Amount int `json:"amount"` } err := json.NewDecoder(req.Body).Decode(&topup) if err != nil { @@ -38,7 +38,7 @@ func (a *api) AddTopup(adminNum int, w http.ResponseWriter, req *http.Request) { Comment: topup.Comment, }, Type: "topup", - Total: topup.Ammount, + Total: topup.Amount, } httpStatus, err := createTransaction(a.db, &transaction) if err != nil { diff --git a/api/topup_test.go b/api/topup_test.go index 1801df5c564d7f563ac55a9e056a07de23048b94..83949566a6250c28dffafa88f697d404e6a3b8a2 100644 --- a/api/topup_test.go +++ b/api/topup_test.go @@ -14,7 +14,7 @@ func TestTopupAddListMine(t *testing.T) { topup := map[string]interface{}{ "member": testMember.Num, "comment": "my topup", - "ammount": 20, + "amount": 20, } resp := tapi.doAdmin("POST", "/topup", topup, nil) if resp.StatusCode != http.StatusCreated { diff --git a/src/ProductPicker.js b/src/ProductPicker.js index e4fe1e794c5470aaae18e91c77a1cea536631f0d..1dd21e0dd886668a14354f15d6e5b33e66e46a94 100644 --- a/src/ProductPicker.js +++ b/src/ProductPicker.js @@ -19,9 +19,9 @@ class ProductPicker extends React.Component { this.props.setPicks(picks); } - setAmmount(index, ammount) { + setAmount(index, amount) { let picks = this.props.picks; - picks[index].ammount = parseInt(ammount); + picks[index].amount = parseInt(amount); this.props.setPicks(picks); } @@ -41,7 +41,7 @@ class ProductPicker extends React.Component { code: product.code, name: product.name, price: product.price, - ammount: 1 + amount: 1 }); this.props.setPicks(picks); this.setState({ code: "" }); @@ -60,13 +60,13 @@ class ProductPicker extends React.Component { <Col> {printMoney(p.price)+"€"} </Col> - {this.props.ammount && + {this.props.amount && <Col> <Form.Control type="number" min="1" placeholder="cantidad" - value={p.ammount} - onChange={e => this.setAmmount(i, e.target.value)} + value={p.amount} + onChange={e => this.setAmount(i, e.target.value)} /> </Col> } @@ -89,7 +89,7 @@ class ProductPicker extends React.Component { <Col> <h6>Precio</h6> </Col> - {this.props.ammount && + {this.props.amount && <Col> <h6>Cantidad</h6> </Col> @@ -116,7 +116,7 @@ class ProductPicker extends React.Component { /> </Col> <Col></Col> - {this.props.ammount && + {this.props.amount && <Col></Col> } <Col sm={1}></Col> diff --git a/src/Topup.js b/src/Topup.js index ecf4fbc787533292fe7503e55f539f7160776b35..0139ab3d83bdcd90704676396ecae518d934a40b 100644 --- a/src/Topup.js +++ b/src/Topup.js @@ -13,7 +13,7 @@ class Topup extends React.Component { this.state = { members: [], numInvalid: false, - ammount: 0, + amount: 0, num: null, name: "", comment: "", @@ -53,7 +53,7 @@ class Topup extends React.Component { const body = JSON.stringify({ member: parseInt(this.state.num), comment: this.state.comment, - ammount: parseInt(this.state.ammount)*100 + amount: parseInt(this.state.amount)*100 }); fetch("/api/topup", {headers: {'x-authentication': this.context.token}, method: "POST", body}) .then(response => { @@ -119,8 +119,8 @@ class Topup extends React.Component { <Form.Control type="number" placeholder="euros" - value={this.state.ammount} - onChange={e => this.setState({ammount: e.target.value})} + value={this.state.amount} + onChange={e => this.setState({amount: e.target.value})} /> <InputGroup.Append> <InputGroup.Text>.00 €</InputGroup.Text> diff --git a/src/purchase/Purchase.js b/src/purchase/Purchase.js index 115e254882d28d0e32feca3fc8bc5e0095415079..0dac522958c35c44c41486576f227ae74189cecf 100644 --- a/src/purchase/Purchase.js +++ b/src/purchase/Purchase.js @@ -21,7 +21,7 @@ class Purchase extends React.Component { } setPurchase(purchase) { - const add = (acc, p) => acc + (p.price*p.ammount); + const add = (acc, p) => acc + (p.price*p.amount); const total = purchase.reduce(add, 0); this.setState({ purchase, total }); } @@ -31,7 +31,7 @@ class Purchase extends React.Component { const body = JSON.stringify(this.state.purchase.map(p => { return { code: p.code, - ammount: p.ammount + amount: p.amount }; })); fetch("/api/purchase", {headers: {'x-authentication': this.context.token}, method: "POST", body}) @@ -83,7 +83,7 @@ class Purchase extends React.Component { return ( <Container> {alert} - <ProductPicker ammount + <ProductPicker amount picks={this.state.purchase} setPicks={purchase => this.setPurchase(purchase)} /> diff --git a/src/purchase/ShowPurchase.js b/src/purchase/ShowPurchase.js index 93a85187192d665fcc06361863237c051817cfc1..0a0da3662c2a9939763cf9b7edb2b2e19ab9bad6 100644 --- a/src/purchase/ShowPurchase.js +++ b/src/purchase/ShowPurchase.js @@ -6,7 +6,7 @@ const columns = [ {dataField: 'code', text: 'Codigo'}, {dataField: 'product.name', text: 'Nombre'}, {dataField: 'price', text: 'Precio', formatter: cell => printMoney(cell)+" €"}, - {dataField: 'ammount', text: 'Cantidad'}, + {dataField: 'amount', text: 'Cantidad'}, ] function ShowPurchase(props) {