summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
Diffstat (limited to 'packages')
-rw-r--r--packages/console/core/script/freeze-workspace.ts39
-rw-r--r--packages/console/core/src/util/price.ts4
2 files changed, 43 insertions, 0 deletions
diff --git a/packages/console/core/script/freeze-workspace.ts b/packages/console/core/script/freeze-workspace.ts
new file mode 100644
index 000000000..d2ccf21ac
--- /dev/null
+++ b/packages/console/core/script/freeze-workspace.ts
@@ -0,0 +1,39 @@
+import { Billing } from "../src/billing.js"
+import { Database, eq } from "../src/drizzle/index.js"
+import { BillingTable } from "../src/schema/billing.sql.js"
+import { WorkspaceTable } from "../src/schema/workspace.sql.js"
+import { microCentsToCents } from "../src/util/price.js"
+
+// get input from command line
+const workspaceID = process.argv[2]
+
+if (!workspaceID) {
+ console.error("Usage: bun freeze-workspace.ts <workspaceID>")
+ process.exit(1)
+}
+
+// check workspace exists
+const workspace = await Database.use((tx) =>
+ tx
+ .select()
+ .from(WorkspaceTable)
+ .where(eq(WorkspaceTable.id, workspaceID))
+ .then((rows) => rows[0]),
+)
+if (!workspace) {
+ console.error("Error: Workspace not found")
+ process.exit(1)
+}
+
+const billing = await Database.use((tx) =>
+ tx
+ .select()
+ .from(BillingTable)
+ .where(eq(BillingTable.workspaceID, workspaceID))
+ .then((rows) => rows[0]),
+)
+
+const amountInDollars = microCentsToCents(billing.balance) / 100
+await Billing.grantCredit(workspaceID, 0 - amountInDollars)
+
+console.log(`Removed payment of $${amountInDollars.toFixed(2)} from workspace ${workspaceID}`)
diff --git a/packages/console/core/src/util/price.ts b/packages/console/core/src/util/price.ts
index abdbca032..ff7a576dd 100644
--- a/packages/console/core/src/util/price.ts
+++ b/packages/console/core/src/util/price.ts
@@ -1,3 +1,7 @@
export function centsToMicroCents(amount: number) {
return Math.round(amount * 1000000)
}
+
+export function microCentsToCents(amount: number) {
+ return Math.round(amount / 1000000)
+}