wip: black
This commit is contained in:
41
packages/console/core/script/black-cancel-waitlist.ts
Normal file
41
packages/console/core/script/black-cancel-waitlist.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import { subscribe } from "diagnostics_channel"
|
||||||
|
import { Billing } from "../src/billing.js"
|
||||||
|
import { and, Database, eq } from "../src/drizzle/index.js"
|
||||||
|
import { BillingTable, PaymentTable, SubscriptionTable } from "../src/schema/billing.sql.js"
|
||||||
|
|
||||||
|
const workspaceID = process.argv[2]
|
||||||
|
|
||||||
|
if (!workspaceID) {
|
||||||
|
console.error("Usage: bun script/foo.ts <workspaceID>")
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(`Removing from Black waitlist`)
|
||||||
|
|
||||||
|
const billing = await Database.use((tx) =>
|
||||||
|
tx
|
||||||
|
.select({
|
||||||
|
subscriptionPlan: BillingTable.subscriptionPlan,
|
||||||
|
timeSubscriptionBooked: BillingTable.timeSubscriptionBooked,
|
||||||
|
})
|
||||||
|
.from(BillingTable)
|
||||||
|
.where(eq(BillingTable.workspaceID, workspaceID))
|
||||||
|
.then((rows) => rows[0]),
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!billing?.timeSubscriptionBooked) {
|
||||||
|
console.error(`Error: Workspace is not on the waitlist`)
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
await Database.use((tx) =>
|
||||||
|
tx
|
||||||
|
.update(BillingTable)
|
||||||
|
.set({
|
||||||
|
subscriptionPlan: null,
|
||||||
|
timeSubscriptionBooked: null,
|
||||||
|
})
|
||||||
|
.where(eq(BillingTable.workspaceID, workspaceID)),
|
||||||
|
)
|
||||||
|
|
||||||
|
console.log(`Done`)
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
import { Billing } from "../src/billing.js"
|
import { Billing } from "../src/billing.js"
|
||||||
|
import { Database, eq } from "../src/drizzle/index.js"
|
||||||
|
import { WorkspaceTable } from "../src/schema/workspace.sql.js"
|
||||||
|
|
||||||
// get input from command line
|
// get input from command line
|
||||||
const workspaceID = process.argv[2]
|
const workspaceID = process.argv[2]
|
||||||
@@ -9,6 +11,19 @@ if (!workspaceID || !dollarAmount) {
|
|||||||
process.exit(1)
|
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 amountInDollars = parseFloat(dollarAmount)
|
const amountInDollars = parseFloat(dollarAmount)
|
||||||
if (isNaN(amountInDollars) || amountInDollars <= 0) {
|
if (isNaN(amountInDollars) || amountInDollars <= 0) {
|
||||||
console.error("Error: dollarAmount must be a positive number")
|
console.error("Error: dollarAmount must be a positive number")
|
||||||
|
|||||||
@@ -113,8 +113,13 @@ async function printWorkspace(workspaceID: string) {
|
|||||||
.select({
|
.select({
|
||||||
balance: BillingTable.balance,
|
balance: BillingTable.balance,
|
||||||
customerID: BillingTable.customerID,
|
customerID: BillingTable.customerID,
|
||||||
subscriptionID: BillingTable.subscriptionID,
|
reload: BillingTable.reload,
|
||||||
subscriptionCouponID: BillingTable.subscriptionCouponID,
|
subscription: {
|
||||||
|
id: BillingTable.subscriptionID,
|
||||||
|
couponID: BillingTable.subscriptionCouponID,
|
||||||
|
plan: BillingTable.subscriptionPlan,
|
||||||
|
booked: BillingTable.timeSubscriptionBooked,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.from(BillingTable)
|
.from(BillingTable)
|
||||||
.where(eq(BillingTable.workspaceID, workspace.id))
|
.where(eq(BillingTable.workspaceID, workspace.id))
|
||||||
@@ -123,6 +128,11 @@ async function printWorkspace(workspaceID: string) {
|
|||||||
rows.map((row) => ({
|
rows.map((row) => ({
|
||||||
...row,
|
...row,
|
||||||
balance: `$${(row.balance / 100000000).toFixed(2)}`,
|
balance: `$${(row.balance / 100000000).toFixed(2)}`,
|
||||||
|
subscription: row.subscription.id
|
||||||
|
? `Subscribed ${row.subscription.couponID ? `(coupon: ${row.subscription.couponID}) ` : ""}`
|
||||||
|
: row.subscription.booked
|
||||||
|
? `Waitlist ${row.subscription.plan} plan`
|
||||||
|
: undefined,
|
||||||
}))[0],
|
}))[0],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user