Skip to content
This repository was archived by the owner on Jan 14, 2020. It is now read-only.

Commit 3244ee9

Browse files
committed
chore: extract get amount to a function
1 parent 527c30e commit 3244ee9

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

dist/bundle.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@
8686
var products = void 0;
8787
var national = void 0;
8888

89+
var getStockAmount = function getStockAmount(stock, product) {
90+
var amount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
91+
92+
if (!isNaN(parseInt(stock[product].amount, 10))) {
93+
amount = stock[product].amount;
94+
} else if (!isNaN(parseInt(stock[product], 10))) {
95+
amount = stock[product];
96+
}
97+
return amount;
98+
};
99+
89100
var getLocation = function getLocation(lgas, states, zones, stockCount) {
90101
if (!stockCount.location) {
91102
return;
@@ -119,7 +130,7 @@
119130

120131
var decoratedStock = Object.keys(stock).reduce(function (decorated, product) {
121132
// v2 stock count report
122-
var amount = stock[product].amount;
133+
var amount = getStockAmount(stock, product);
123134
var status = void 0;
124135
var allocation = void 0;
125136
var productThresholds = void 0;

dist/bundle.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/state-indicators.service.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,15 @@ class StateIndicatorsService {
7373
let products
7474
let national
7575

76+
const getStockAmount = (stock, product, amount = 0) => {
77+
if (!isNaN(parseInt(stock[product].amount, 10))) {
78+
amount = stock[product].amount
79+
} else if (!isNaN(parseInt(stock[product], 10))) {
80+
amount = stock[product]
81+
}
82+
return amount
83+
}
84+
7685
const getLocation = (lgas, states, zones, stockCount) => {
7786
if (!stockCount.location) {
7887
return
@@ -104,12 +113,7 @@ class StateIndicatorsService {
104113

105114
const decoratedStock = Object.keys(stock).reduce((decorated, product) => {
106115
// v2 stock count report
107-
let amount = 0
108-
if (!isNaN(parseInt(stock[product].amount, 10))) {
109-
amount = stock[product].amount
110-
} else if (!isNaN(parseInt(stock[product], 10))) {
111-
amount = stock[product]
112-
}
116+
const amount = getStockAmount(stock, product)
113117
let status
114118
let allocation
115119
let productThresholds

0 commit comments

Comments
 (0)