kopia lustrzana https://github.com/transitive-bullshit/chatgpt-api
pull/715/head
rodzic
903d052548
commit
612519ec68
|
@ -1,11 +1,11 @@
|
|||
import { createRoute, type OpenAPIHono } from '@hono/zod-openapi'
|
||||
|
||||
import type { AuthenticatedEnv } from '@/lib/types'
|
||||
import { db, eq, populateProjectSchema, schema } from '@/db'
|
||||
import { db, eq, schema } from '@/db'
|
||||
import { acl } from '@/lib/acl'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { ProjectIdParamsSchema } from './schemas'
|
||||
import { populateProjectSchema, projectIdParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Gets a project',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'projects/{projectId}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: ProjectIdParamsSchema,
|
||||
params: projectIdParamsSchema,
|
||||
query: populateProjectSchema
|
||||
},
|
||||
responses: {
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import { createRoute, type OpenAPIHono, z } from '@hono/zod-openapi'
|
||||
|
||||
import type { AuthenticatedEnv } from '@/lib/types'
|
||||
import { db, eq, paginationSchema, schema } from '@/db'
|
||||
import { db, eq, schema } from '@/db'
|
||||
import { parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { paginationAndPopulateProjectSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Lists projects the authenticated user has access to.',
|
||||
tags: ['projects'],
|
||||
|
@ -12,7 +14,7 @@ const route = createRoute({
|
|||
path: 'projects',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
query: paginationSchema
|
||||
query: paginationAndPopulateProjectSchema
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
|
@ -36,7 +38,8 @@ export function registerV1ProjectsListProjects(
|
|||
offset = 0,
|
||||
limit = 10,
|
||||
sort = 'desc',
|
||||
sortBy = 'createdAt'
|
||||
sortBy = 'createdAt',
|
||||
populate = []
|
||||
} = c.req.valid('query')
|
||||
|
||||
const user = c.get('user')
|
||||
|
@ -50,7 +53,8 @@ export function registerV1ProjectsListProjects(
|
|||
? eq(schema.projects.teamId, teamMember.teamId)
|
||||
: eq(schema.projects.userId, user.id),
|
||||
with: {
|
||||
lastPublishedDeployment: true
|
||||
lastPublishedDeployment: true,
|
||||
...Object.fromEntries(populate.map((field) => [field, true]))
|
||||
},
|
||||
orderBy: (projects, { asc, desc }) => [
|
||||
sort === 'desc' ? desc(projects[sortBy]) : asc(projects[sortBy])
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import { z } from '@hono/zod-openapi'
|
||||
|
||||
import { projectIdSchema } from '@/db'
|
||||
import { paginationSchema, projectIdSchema } from '@/db'
|
||||
import { projectRelationsSchema } from '@/db/schema'
|
||||
|
||||
export const ProjectIdParamsSchema = z.object({
|
||||
export const projectIdParamsSchema = z.object({
|
||||
projectId: projectIdSchema.openapi({
|
||||
param: {
|
||||
description: 'Project ID',
|
||||
|
@ -11,3 +12,12 @@ export const ProjectIdParamsSchema = z.object({
|
|||
}
|
||||
})
|
||||
})
|
||||
|
||||
export const populateProjectSchema = z.object({
|
||||
populate: z.array(projectRelationsSchema).default([]).optional()
|
||||
})
|
||||
|
||||
export const paginationAndPopulateProjectSchema = z.object({
|
||||
...paginationSchema.shape,
|
||||
...populateProjectSchema.shape
|
||||
})
|
||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
|||
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { TeamSlugParamsSchema } from './schemas'
|
||||
import { teamSlugParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Deletes a team by slug.',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'teams/{team}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: TeamSlugParamsSchema
|
||||
params: teamSlugParamsSchema
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
|||
import { aclTeamMember } from '@/lib/acl-team-member'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { TeamSlugParamsSchema } from './schemas'
|
||||
import { teamSlugParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Gets a team by slug.',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'teams/{team}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: TeamSlugParamsSchema
|
||||
params: teamSlugParamsSchema
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { and, db, eq, schema } from '@/db'
|
|||
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { TeamSlugParamsSchema } from '../schemas'
|
||||
import { teamSlugParamsSchema } from '../schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Creates a team member.',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'teams/{team}/members',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: TeamSlugParamsSchema,
|
||||
params: teamSlugParamsSchema,
|
||||
body: {
|
||||
required: true,
|
||||
content: {
|
||||
|
|
|
@ -6,8 +6,7 @@ import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
|||
import { aclTeamMember } from '@/lib/acl-team-member'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { TeamSlugParamsSchema } from '../schemas'
|
||||
import { TeamMemberUserIdParamsSchema } from './schemas'
|
||||
import { teamSlugTeamMemberUserIdParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Deletes a team member.',
|
||||
|
@ -17,7 +16,7 @@ const route = createRoute({
|
|||
path: 'teams/{team}/members/{userId}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: TeamSlugParamsSchema.merge(TeamMemberUserIdParamsSchema)
|
||||
params: teamSlugTeamMemberUserIdParamsSchema
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
|
@ -54,7 +53,7 @@ export function registerV1TeamsMembersDeleteTeamMember(
|
|||
assert(
|
||||
teamMember,
|
||||
404,
|
||||
`Team member "${userId}" for team "${teamSlug}" not found`
|
||||
`Failed to update team member "${userId}" for team "${teamSlug}"`
|
||||
)
|
||||
|
||||
return c.json(parseZodSchema(schema.teamMemberSelectSchema, teamMember))
|
||||
|
|
|
@ -2,7 +2,10 @@ import { z } from '@hono/zod-openapi'
|
|||
|
||||
import { userIdSchema } from '@/db'
|
||||
|
||||
export const TeamMemberUserIdParamsSchema = z.object({
|
||||
import { teamSlugParamsSchema } from '../schemas'
|
||||
|
||||
export const teamSlugTeamMemberUserIdParamsSchema = z.object({
|
||||
...teamSlugParamsSchema.shape,
|
||||
userId: userIdSchema.openapi({
|
||||
param: {
|
||||
description: 'Team member user ID',
|
||||
|
|
|
@ -6,8 +6,7 @@ import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
|||
import { aclTeamMember } from '@/lib/acl-team-member'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { TeamSlugParamsSchema } from '../schemas'
|
||||
import { TeamMemberUserIdParamsSchema } from './schemas'
|
||||
import { teamSlugTeamMemberUserIdParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Updates a team member.',
|
||||
|
@ -17,7 +16,7 @@ const route = createRoute({
|
|||
path: 'teams/{team}/members/{userId}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: TeamSlugParamsSchema.merge(TeamMemberUserIdParamsSchema),
|
||||
params: teamSlugTeamMemberUserIdParamsSchema,
|
||||
body: {
|
||||
required: true,
|
||||
content: {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { z } from '@hono/zod-openapi'
|
|||
|
||||
import { teamSlugSchema } from '@/db'
|
||||
|
||||
export const TeamSlugParamsSchema = z.object({
|
||||
export const teamSlugParamsSchema = z.object({
|
||||
team: teamSlugSchema.openapi({
|
||||
param: {
|
||||
description: 'Team slug',
|
||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
|||
import { aclTeamAdmin } from '@/lib/acl-team-admin'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { TeamSlugParamsSchema } from './schemas'
|
||||
import { teamSlugParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Updates a team.',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'teams/{team}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: TeamSlugParamsSchema,
|
||||
params: teamSlugParamsSchema,
|
||||
body: {
|
||||
required: true,
|
||||
content: {
|
||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
|||
import { acl } from '@/lib/acl'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { UserIdParamsSchema } from './schemas'
|
||||
import { userIdParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Gets a user',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'users/{userId}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: UserIdParamsSchema
|
||||
params: userIdParamsSchema
|
||||
},
|
||||
responses: {
|
||||
200: {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { z } from '@hono/zod-openapi'
|
|||
|
||||
import { userIdSchema } from '@/db'
|
||||
|
||||
export const UserIdParamsSchema = z.object({
|
||||
export const userIdParamsSchema = z.object({
|
||||
userId: userIdSchema.openapi({
|
||||
param: {
|
||||
description: 'User ID',
|
||||
|
|
|
@ -5,7 +5,7 @@ import { db, eq, schema } from '@/db'
|
|||
import { acl } from '@/lib/acl'
|
||||
import { assert, parseZodSchema } from '@/lib/utils'
|
||||
|
||||
import { UserIdParamsSchema } from './schemas'
|
||||
import { userIdParamsSchema } from './schemas'
|
||||
|
||||
const route = createRoute({
|
||||
description: 'Updates a user',
|
||||
|
@ -15,7 +15,7 @@ const route = createRoute({
|
|||
path: 'users/{userId}',
|
||||
security: [{ bearerAuth: [] }],
|
||||
request: {
|
||||
params: UserIdParamsSchema,
|
||||
params: userIdParamsSchema,
|
||||
body: {
|
||||
required: true,
|
||||
content: {
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
import { validators } from '@agentic/validators'
|
||||
import { z } from '@hono/zod-openapi'
|
||||
|
||||
import { projectRelationsSchema } from './schema/project'
|
||||
|
||||
function getCuidSchema(idLabel: string) {
|
||||
return z.string().refine((id) => validators.cuid(id), {
|
||||
message: `Invalid ${idLabel}`
|
||||
|
@ -43,10 +41,6 @@ export const paginationSchema = z.object({
|
|||
sortBy: z.enum(['createdAt', 'updatedAt']).default('createdAt').optional()
|
||||
})
|
||||
|
||||
export const populateProjectSchema = z.object({
|
||||
populate: z.array(projectRelationsSchema).default([]).optional()
|
||||
})
|
||||
|
||||
// import type { PgTable, TableConfig } from '@fisch0920/drizzle-orm/pg-core'
|
||||
// import type { AnyZodObject } from 'zod'
|
||||
//
|
||||
|
|
Ładowanie…
Reference in New Issue