kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
feat: WIP stripe billing refactor update for 2025
rodzic
78d8e13250
commit
7bc65beba4
|
@ -15,7 +15,8 @@ import { parseZodSchema } from '@/lib/utils'
|
|||
import { consumerIdParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: "Updates a consumer's subscription to a project.",
|
||||
description:
|
||||
"Updates a consumer's subscription to a different deployment or pricing plan.",
|
||||
tags: ['consumers'],
|
||||
operationId: 'updateConsumer',
|
||||
method: 'post',
|
||||
|
|
|
@ -60,9 +60,9 @@ export function registerV1ProjectsCreateProject(
|
|||
.insert(schema.projects)
|
||||
.values({
|
||||
...body,
|
||||
id,
|
||||
teamId: teamMember?.teamId,
|
||||
userId: user.id,
|
||||
id,
|
||||
_secret: sha256(),
|
||||
_providerToken: createProviderToken({ id })
|
||||
})
|
||||
|
|
|
@ -2,6 +2,7 @@ import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
|||
|
||||
import type { AuthenticatedEnv } from '@/lib/types'
|
||||
import { db, eq, schema } from '@/db'
|
||||
import { acl } from '@/lib/acl'
|
||||
import {
|
||||
openapiAuthenticatedSecuritySchemas,
|
||||
openapiErrorResponse404,
|
||||
|
@ -50,7 +51,15 @@ export function registerV1ProjectsUpdateProject(
|
|||
const { projectId } = c.req.valid('param')
|
||||
const body = c.req.valid('json')
|
||||
|
||||
const [project] = await db
|
||||
// First ensure the project exists and the user has access to it
|
||||
let project = await db.query.projects.findFirst({
|
||||
where: eq(schema.projects.id, projectId)
|
||||
})
|
||||
assert(project, 404, `Project not found "${projectId}"`)
|
||||
await acl(c, project, { label: 'Project' })
|
||||
|
||||
// Update the project
|
||||
;[project] = await db
|
||||
.update(schema.projects)
|
||||
.set(body)
|
||||
.where(eq(schema.projects.id, projectId))
|
||||
|
|
|
@ -78,7 +78,7 @@ export function registerV1TeamsMembersCreateTeamMember(
|
|||
})
|
||||
assert(
|
||||
teamMember,
|
||||
400,
|
||||
500,
|
||||
`Failed to create team member "${body.userId}"for team "${teamSlug}"`
|
||||
)
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ export function registerV1TeamsMembersDeleteTeamMember(
|
|||
.returning()
|
||||
assert(
|
||||
teamMember,
|
||||
404,
|
||||
400,
|
||||
`Failed to update team member "${userId}" for team "${teamSlug}"`
|
||||
)
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ export async function upsertConsumer(
|
|||
}
|
||||
) {
|
||||
assert(consumerId || deploymentId, 400, 'Missing required "deploymentId"')
|
||||
const logger = c.get('logger')
|
||||
const userId = c.get('userId')
|
||||
let projectId: string | undefined
|
||||
|
||||
|
@ -147,7 +148,6 @@ export async function upsertConsumer(
|
|||
// consumer._stripeAccount = project._stripeAccount
|
||||
await upsertStripeConnectCustomer({ stripeCustomer, consumer, project })
|
||||
|
||||
const logger = c.get('logger')
|
||||
logger.info('SUBSCRIPTION', existingConsumer ? 'UPDATE' : 'CREATE', {
|
||||
project,
|
||||
deployment,
|
||||
|
|
|
@ -18,6 +18,6 @@ export async function ensureUniqueTeamSlug(slug: string) {
|
|||
assert(
|
||||
!existingUser && !existingTeam,
|
||||
409,
|
||||
`Team slug [${slug}] is not available`
|
||||
`Team slug "${slug}" is not available`
|
||||
)
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue