mirror of
https://github.com/simstudioai/sim.git
synced 2026-02-14 16:35:01 -05:00
improvement(api-keys): move to workspace level (#1765)
* 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>
This commit is contained in:
committed by
GitHub
parent
c99bb0aaa2
commit
fe9ebbf81b
39
apps/sim/lib/workspaces/utils.ts
Normal file
39
apps/sim/lib/workspaces/utils.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user