I'm pretty new to front end and programming in general. This my code snippet:
addPerson() {
//this.addInventory()
let url = "http://localhost:8080/savefood/persons";
axios.post(url, this.person).then(response => {
console.log(response.data);
this.updateInventory(response.data.idPerson, this.addInventory())});
// reset input fields
this.person = {};
},
addInventory() {
let url = "http://localhost:8080/savefood/inventories";
axios.post(url, this.inventory).then(response => {
console.log(response.data)});
// reset input fields
this.inventory = {};
},
What I'm trying to do is to return from addInventory()
an idInventory
which will be created with the axios.post()
.I'm failing at all my attempts. Is there a way to extract the idInventory
from the response and then return it? My goal is to return the idInventory
from addInventory()
so that updateInventory(...)
is able to work properly. If I simply replace this.addInventory()
in updateInventory(..)
with an id of an existing inventory it will work fine. But I want to be able to create an inventory and a person and then attach the just created inventory to the person. Thanks for your help!