This commit is contained in:
Frank
2026-03-23 22:24:58 -04:00
parent a03a2b6eab
commit a8b28826a0
+30 -14
View File
@@ -1,7 +1,14 @@
import { Database, and, eq, sql } from "../src/drizzle/index.js" import { Database, and, eq, sql } from "../src/drizzle/index.js"
import { AuthTable } from "../src/schema/auth.sql.js" import { AuthTable } from "../src/schema/auth.sql.js"
import { UserTable } from "../src/schema/user.sql.js" import { UserTable } from "../src/schema/user.sql.js"
import { BillingTable, PaymentTable, SubscriptionTable, BlackPlans, UsageTable } from "../src/schema/billing.sql.js" import {
BillingTable,
PaymentTable,
SubscriptionTable,
BlackPlans,
UsageTable,
LiteTable,
} from "../src/schema/billing.sql.js"
import { WorkspaceTable } from "../src/schema/workspace.sql.js" import { WorkspaceTable } from "../src/schema/workspace.sql.js"
import { KeyTable } from "../src/schema/key.sql.js" import { KeyTable } from "../src/schema/key.sql.js"
import { BlackData } from "../src/black.js" import { BlackData } from "../src/black.js"
@@ -72,11 +79,13 @@ else {
workspaceID: UserTable.workspaceID, workspaceID: UserTable.workspaceID,
workspaceName: WorkspaceTable.name, workspaceName: WorkspaceTable.name,
role: UserTable.role, role: UserTable.role,
subscribed: SubscriptionTable.timeCreated, black: SubscriptionTable.timeCreated,
lite: LiteTable.timeCreated,
}) })
.from(UserTable) .from(UserTable)
.rightJoin(WorkspaceTable, eq(WorkspaceTable.id, UserTable.workspaceID)) .rightJoin(WorkspaceTable, eq(WorkspaceTable.id, UserTable.workspaceID))
.leftJoin(SubscriptionTable, eq(SubscriptionTable.userID, UserTable.id)) .leftJoin(SubscriptionTable, eq(SubscriptionTable.userID, UserTable.id))
.leftJoin(LiteTable, eq(LiteTable.userID, UserTable.id))
.where(eq(UserTable.accountID, accountID)) .where(eq(UserTable.accountID, accountID))
.then((rows) => .then((rows) =>
rows.map((row) => ({ rows.map((row) => ({
@@ -84,7 +93,8 @@ else {
workspaceID: row.workspaceID, workspaceID: row.workspaceID,
workspaceName: row.workspaceName, workspaceName: row.workspaceName,
role: row.role, role: row.role,
subscribed: formatDate(row.subscribed), black: formatDate(row.black),
lite: formatDate(row.lite),
})), })),
), ),
) )
@@ -151,13 +161,14 @@ async function printWorkspace(workspaceID: string) {
balance: BillingTable.balance, balance: BillingTable.balance,
customerID: BillingTable.customerID, customerID: BillingTable.customerID,
reload: BillingTable.reload, reload: BillingTable.reload,
subscriptionID: BillingTable.subscriptionID, blackSubscriptionID: BillingTable.subscriptionID,
subscription: { blackSubscription: {
plan: BillingTable.subscriptionPlan, plan: BillingTable.subscriptionPlan,
booked: BillingTable.timeSubscriptionBooked, booked: BillingTable.timeSubscriptionBooked,
enrichment: BillingTable.subscription, enrichment: BillingTable.subscription,
}, },
timeSubscriptionSelected: BillingTable.timeSubscriptionSelected, timeBlackSubscriptionSelected: BillingTable.timeSubscriptionSelected,
liteSubscriptionID: BillingTable.liteSubscriptionID,
}) })
.from(BillingTable) .from(BillingTable)
.where(eq(BillingTable.workspaceID, workspace.id)) .where(eq(BillingTable.workspaceID, workspace.id))
@@ -167,16 +178,21 @@ async function printWorkspace(workspaceID: string) {
balance: `$${(row.balance / 100000000).toFixed(2)}`, balance: `$${(row.balance / 100000000).toFixed(2)}`,
reload: row.reload ? "yes" : "no", reload: row.reload ? "yes" : "no",
customerID: row.customerID, customerID: row.customerID,
subscriptionID: row.subscriptionID, liteSubscriptionID: row.liteSubscriptionID,
subscription: row.subscriptionID blackSubscriptionID: row.blackSubscriptionID,
blackSubscription: row.blackSubscriptionID
? [ ? [
`Black ${row.subscription.enrichment!.plan}`, `Black ${row.blackSubscription.enrichment!.plan}`,
row.subscription.enrichment!.seats > 1 ? `X ${row.subscription.enrichment!.seats} seats` : "", row.blackSubscription.enrichment!.seats > 1
row.subscription.enrichment!.coupon ? `(coupon: ${row.subscription.enrichment!.coupon})` : "", ? `X ${row.blackSubscription.enrichment!.seats} seats`
`(ref: ${row.subscriptionID})`, : "",
row.blackSubscription.enrichment!.coupon
? `(coupon: ${row.blackSubscription.enrichment!.coupon})`
: "",
`(ref: ${row.blackSubscriptionID})`,
].join(" ") ].join(" ")
: row.subscription.booked : row.blackSubscription.booked
? `Waitlist ${row.subscription.plan} plan${row.timeSubscriptionSelected ? " (selected)" : ""}` ? `Waitlist ${row.blackSubscription.plan} plan${row.timeBlackSubscriptionSelected ? " (selected)" : ""}`
: undefined, : undefined,
}))[0], }))[0],
), ),