Sunday, 14 May 2017

Node JS api route validation returning wrong output

In this code i'm trying to return a json object which are going to fulfill my condition. In my point of view i don't see any problem in this code even though it gives me a wrong output.

this is a part of an node js api code. this is my api route and iam coding this inside a get request and iam returning my newly created json as res.json. problem is iam getting invalid output such as i'm comparing reorderlevel against amount of amount is less than or equal to reorder level iam adding that record to a json and returning it.

Eg if my json is [{ "name":"test", "amount":200, "reorderlevel":100

}, { "name":"test2", "amount":70, "reorderlevel":100

}]

I want to get only the 2nd element of the json where name is "test2" and amount is less than reorder level but iam getting the wrong json element :|

   for (var i = 0; i < stockDetails.length; i++) {


            if (stockDetails[i].amount <= stockDetails[i].reorderlevel) {
                reorderAlert.push({
                    id : i,
                    drugName: stockDetails[i].name,
                    availableAmount: stockDetails[i].amount,
                    reorderLevel: stockDetails[i].reorderlevel
                });
            }       
        }



via yinza

No comments:

Post a Comment