Skip to content

Commit

Permalink
Refactor external data usage handling in storage.ostrich.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
Cosmin-Parvulescu committed Feb 28, 2024
1 parent b28c9b6 commit f7a3a15
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions apps/console/app/routes/apps/$clientId/storage.ostrich.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
const newPackageType = fd.get('package') as ExternalAppDataPackageType
const autoTopUp = fd.get('top-up') !== '0'

const { readUsage, writeUsage, readTopUp, writeTopUp } =
const externalDataUsage =
await coreClient.starbase.getAppExternalDataUsage.query({
clientId: params.clientId as string,
})
Expand Down Expand Up @@ -177,25 +177,29 @@ export const action: ActionFunction = getRollupReqFunctionErrorWrapper(
autoTopUp,
})

const forceTopUp =
(readUsage &&
readUsage >
ExternalAppDataPackages[newPackageType].reads + readTopUp) ||
(writeUsage &&
writeUsage >
ExternalAppDataPackages[newPackageType].writes + writeTopUp)
if (appDetails.externalAppDataPackageDefinition && forceTopUp) {
await createInvoice(
env.SECRET_STRIPE_API_KEY,
spd.customerID,
sub.id,
packageTypeToTopUpPriceID(
env,
appDetails.externalAppDataPackageDefinition.packageDetails
.packageType
),
true
)
if (externalDataUsage) {
const { readUsage, writeUsage, readTopUp, writeTopUp } =
externalDataUsage
const forceTopUp =
(readUsage &&
readUsage >
ExternalAppDataPackages[newPackageType].reads + readTopUp) ||
(writeUsage &&
writeUsage >
ExternalAppDataPackages[newPackageType].writes + writeTopUp)
if (appDetails.externalAppDataPackageDefinition && forceTopUp) {
await createInvoice(
env.SECRET_STRIPE_API_KEY,
spd.customerID,
sub.id,
packageTypeToTopUpPriceID(
env,
appDetails.externalAppDataPackageDefinition.packageDetails
.packageType
),
true
)
}
}

break
Expand Down

0 comments on commit f7a3a15

Please sign in to comment.