mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-19 08:44:22 +01:00
wip: zen
This commit is contained in:
@@ -2,17 +2,7 @@ import "./workspace.css"
|
||||
import { useAuthSession } from "~/context/auth.session"
|
||||
import { IconLogo } from "../component/icon"
|
||||
import { withActor } from "~/context/auth.withActor"
|
||||
import {
|
||||
query,
|
||||
action,
|
||||
redirect,
|
||||
createAsync,
|
||||
RouteSectionProps,
|
||||
Navigate,
|
||||
useNavigate,
|
||||
useParams,
|
||||
A,
|
||||
} from "@solidjs/router"
|
||||
import { query, action, redirect, createAsync, RouteSectionProps, useParams, A } from "@solidjs/router"
|
||||
import { User } from "@opencode/console-core/user.js"
|
||||
import { Actor } from "@opencode/console-core/actor.js"
|
||||
import { getRequestEvent } from "solid-js/web"
|
||||
@@ -21,7 +11,8 @@ const getUserInfo = query(async (workspaceID: string) => {
|
||||
"use server"
|
||||
return withActor(async () => {
|
||||
const actor = Actor.assert("user")
|
||||
return await User.fromID(actor.properties.userID)
|
||||
const email = await User.getAccountEmail(actor.properties.userID)
|
||||
return { email }
|
||||
}, workspaceID)
|
||||
}, "userInfo")
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ import { z } from "zod"
|
||||
import { Resource } from "@opencode/console-resource"
|
||||
import { Identifier } from "./identifier"
|
||||
import { centsToMicroCents } from "./util/price"
|
||||
import { UserTable } from "./schema/user.sql"
|
||||
import { AccountTable } from "./schema/account.sql"
|
||||
import { User } from "./user"
|
||||
|
||||
export namespace Billing {
|
||||
export const CHARGE_NAME = "opencode credits"
|
||||
@@ -172,16 +171,7 @@ export namespace Billing {
|
||||
const user = Actor.assert("user")
|
||||
const { successUrl, cancelUrl } = input
|
||||
|
||||
const email = await Database.use((tx) =>
|
||||
tx
|
||||
.select({
|
||||
email: AccountTable.email,
|
||||
})
|
||||
.from(UserTable)
|
||||
.innerJoin(AccountTable, eq(UserTable.accountID, AccountTable.id))
|
||||
.where(and(eq(UserTable.id, user.properties.userID), eq(UserTable.workspaceID, Actor.workspace())))
|
||||
.then((rows) => rows[0]?.email),
|
||||
)
|
||||
const email = await User.getAccountEmail(user.properties.userID)
|
||||
const customer = await Billing.get()
|
||||
const session = await Billing.stripe().checkout.sessions.create({
|
||||
mode: "payment",
|
||||
@@ -216,7 +206,7 @@ export namespace Billing {
|
||||
},
|
||||
}
|
||||
: {
|
||||
customer_email: email,
|
||||
customer_email: email!,
|
||||
customer_creation: "always",
|
||||
}),
|
||||
currency: "usd",
|
||||
|
||||
@@ -50,6 +50,19 @@ export namespace User {
|
||||
),
|
||||
)
|
||||
|
||||
export const getAccountEmail = fn(z.string(), (id) =>
|
||||
Database.use((tx) =>
|
||||
tx
|
||||
.select({
|
||||
email: AccountTable.email,
|
||||
})
|
||||
.from(UserTable)
|
||||
.leftJoin(AccountTable, eq(UserTable.accountID, AccountTable.id))
|
||||
.where(and(eq(UserTable.workspaceID, Actor.workspace()), eq(UserTable.id, id)))
|
||||
.then((rows) => rows[0]?.email),
|
||||
),
|
||||
)
|
||||
|
||||
export const invite = fn(
|
||||
z.object({
|
||||
email: z.string(),
|
||||
|
||||
Reference in New Issue
Block a user