diff options
| author | Frank <[email protected]> | 2025-08-08 13:22:54 -0400 |
|---|---|---|
| committer | Frank <[email protected]> | 2025-08-08 13:24:32 -0400 |
| commit | 183e0911b76025a1f2a82e979d9834fec2131d0e (patch) | |
| tree | 9987c1753bd64d1ce1d174ab397f1a8c681f642c /cloud/core/src/workspace.ts | |
| parent | c7bb19ad0712469063eab35589aa5d3602b0c5b1 (diff) | |
| download | opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.tar.gz opencode-183e0911b76025a1f2a82e979d9834fec2131d0e.zip | |
wip: gateway
Diffstat (limited to 'cloud/core/src/workspace.ts')
| -rw-r--r-- | cloud/core/src/workspace.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/cloud/core/src/workspace.ts b/cloud/core/src/workspace.ts new file mode 100644 index 000000000..532b22963 --- /dev/null +++ b/cloud/core/src/workspace.ts @@ -0,0 +1,48 @@ +import { z } from "zod" +import { fn } from "./util/fn" +import { centsToMicroCents } from "./util/price" +import { Actor } from "./actor" +import { Database, eq } from "./drizzle" +import { Identifier } from "./identifier" +import { UserTable } from "./schema/user.sql" +import { BillingTable } from "./schema/billing.sql" +import { WorkspaceTable } from "./schema/workspace.sql" + +export namespace Workspace { + export const create = fn(z.void(), async () => { + const account = Actor.assert("account") + const workspaceID = Identifier.create("workspace") + await Database.transaction(async (tx) => { + await tx.insert(WorkspaceTable).values({ + id: workspaceID, + }) + await tx.insert(UserTable).values({ + workspaceID, + id: Identifier.create("user"), + email: account.properties.email, + name: "", + }) + await tx.insert(BillingTable).values({ + workspaceID, + id: Identifier.create("billing"), + balance: centsToMicroCents(100), + }) + }) + return workspaceID + }) + + export async function list() { + const account = Actor.assert("account") + return Database.use(async (tx) => { + return tx + .select({ + id: WorkspaceTable.id, + slug: WorkspaceTable.slug, + name: WorkspaceTable.name, + }) + .from(UserTable) + .innerJoin(WorkspaceTable, eq(UserTable.workspaceID, WorkspaceTable.id)) + .where(eq(UserTable.email, account.properties.email)) + }) + } +} |
