File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 } ` )
Original file line number Diff line number Diff line change 11export 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+ }
You can’t perform that action at this time.
0 commit comments