Merge pull request #6761 from supabase/fix/NaN-billing-results

Fix/NaN billing results
This commit is contained in:
Copple authored and GitHub committed 2022-05-23 18:49:07 +10:00
commit cd8055dbf1
1 file changed
+7 -3
@@ -50,18 +50,22 @@ function getPaygStats(data: any): PaygStats {
let dataModified: any = []
data.map((x: any) => {
dataModified.push({ ...x, total_egress_modified: x.total_egress - x.total_storage_egress })
dataModified.push({ ...x, total_egress_modified: x.total_egress == undefined ? 0 : x.total_egress - x.total_storage_egress == undefined ? 0 : x.total_storage_egress })
})
chargeableProducts.forEach((product) => {
product.features.forEach((feature) => {
// calculate max
const max = _get(maxBy(dataModified, feature.attribute), feature.attribute)
const max = _get(maxBy(dataModified, feature.attribute), feature.attribute) ?? 0
// calculate sum
let sum = 0
dataModified.map((x: any) => {
sum = sum + x[feature.attribute]
const featureAttribute = x[feature.attribute] == undefined ? 0 : x[feature.attribute]
sum = sum + featureAttribute
})
// set sum and max under attribute name
paygStats[feature.attribute] = {
sum,