Skip to content

Commit f7c2ef8

Browse files
committed
wip: zen
1 parent 6639f92 commit f7c2ef8

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { Billing } from "../src/billing.js"
2+
import { Database, eq } from "../src/drizzle/index.js"
3+
import { BillingTable } from "../src/schema/billing.sql.js"
4+
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
5+
import { microCentsToCents } from "../src/util/price.js"
6+
7+
// get input from command line
8+
const workspaceID = process.argv[2]
9+
10+
if (!workspaceID) {
11+
console.error("Usage: bun freeze-workspace.ts <workspaceID>")
12+
process.exit(1)
13+
}
14+
15+
// check workspace exists
16+
const workspace = await Database.use((tx) =>
17+
tx
18+
.select()
19+
.from(WorkspaceTable)
20+
.where(eq(WorkspaceTable.id, workspaceID))
21+
.then((rows) => rows[0]),
22+
)
23+
if (!workspace) {
24+
console.error("Error: Workspace not found")
25+
process.exit(1)
26+
}
27+
28+
const billing = await Database.use((tx) =>
29+
tx
30+
.select()
31+
.from(BillingTable)
32+
.where(eq(BillingTable.workspaceID, workspaceID))
33+
.then((rows) => rows[0]),
34+
)
35+
36+
const amountInDollars = microCentsToCents(billing.balance) / 100
37+
await Billing.grantCredit(workspaceID, 0 - amountInDollars)
38+
39+
console.log(`Removed payment of $${amountInDollars.toFixed(2)} from workspace ${workspaceID}`)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export function centsToMicroCents(amount: number) {
22
return Math.round(amount * 1000000)
33
}
4+
5+
export function microCentsToCents(amount: number) {
6+
return Math.round(amount / 1000000)
7+
}

0 commit comments

Comments
 (0)