0
I have a API that makes the POST of Item in the database, but before doing the POST she makes a GET to obtain a code for the Item that will be saved.
NOTE: this code cannot be repeated in the database, it has to be unique.
When sending an array with two items, they are taking the same code, giving conflict when writing to DB.
The two items pass on line 102, and then the two items pass on line 113.
How to make one item at a time get the code and then save to the bank so the next items do the same process?
Have you ever tried to make a foreach when you have more than 01 item ? So you will record one item at a time and get a new code for the item at each iteration.
– JcSaint
I already have a FOR in the application that sends item by item to the API.
– leopiazzoli
put the code of that part there. :)
– JcSaint
for (var i = 0; i < $rootScope.itemObj.length; i++) {
 Prevendas.incluirItemPreVenda($rootScope.itemObj[i]).success(function () {
 console.log("incluirItemPreVenda OK");
 }).error(function () {
 console.log("incluirItemPreVenda Erro");
 })
}
– leopiazzoli
This is happening because you are making several asynchronous calls, which database are you using? There is no possibility to put this field as identitiy/autoincrement?
– João Mello
Which database you use?
– Ricardo
dbc database, but I can’t use autoincrement because I can’t change the database because it’s used by another desktop system.
– leopiazzoli