mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-06 20:55:23 -05:00
* fix(billing): should allow restoring subscription (#1728) * fix(already-cancelled-sub): UI should allow restoring subscription * restore functionality fixed * fix * improvement(api-keys): move to workspace level * remove migration to prep merge * remove two more unused cols * prep staging merge * add migration back --------- Co-authored-by: Waleed <walif6@gmail.com> Co-authored-by: Siddharth Ganesan <33737564+Sg312@users.noreply.github.com>
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { db } from '@sim/db'
|
|
import { workspace as workspaceTable } from '@sim/db/schema'
|
|
import { eq } from 'drizzle-orm'
|
|
|
|
interface WorkspaceBillingSettings {
|
|
billedAccountUserId: string | null
|
|
allowPersonalApiKeys: boolean
|
|
}
|
|
|
|
export async function getWorkspaceBillingSettings(
|
|
workspaceId: string
|
|
): Promise<WorkspaceBillingSettings | null> {
|
|
if (!workspaceId) {
|
|
return null
|
|
}
|
|
|
|
const rows = await db
|
|
.select({
|
|
billedAccountUserId: workspaceTable.billedAccountUserId,
|
|
allowPersonalApiKeys: workspaceTable.allowPersonalApiKeys,
|
|
})
|
|
.from(workspaceTable)
|
|
.where(eq(workspaceTable.id, workspaceId))
|
|
.limit(1)
|
|
|
|
if (!rows.length) {
|
|
return null
|
|
}
|
|
|
|
return {
|
|
billedAccountUserId: rows[0].billedAccountUserId ?? null,
|
|
allowPersonalApiKeys: rows[0].allowPersonalApiKeys ?? false,
|
|
}
|
|
}
|
|
|
|
export async function getWorkspaceBilledAccountUserId(workspaceId: string): Promise<string | null> {
|
|
const settings = await getWorkspaceBillingSettings(workspaceId)
|
|
return settings?.billedAccountUserId ?? null
|
|
}
|