Skip to content

Commit 6a53e37

Browse files
committed
fix: with validator problem
1 parent 38ad227 commit 6a53e37

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

packages/core/src/endpoint.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { z, ZodType } from 'zod'
44
import zodToJsonSchema from 'zod-to-json-schema'
55

66
import type { MaybePromise } from './collection'
7+
import { withValidator } from './utils'
78

89
export type ApiHttpStatus = 200 | 201 | 204 | 301 | 302 | 400 | 401 | 403 | 404 | 409 | 422 | 500
910

@@ -166,8 +167,8 @@ export function createEndpoint<
166167
>(schema: TApiEndpointSchema, handler: ApiRouteHandler<TContext, TApiEndpointSchema>) {
167168
return {
168169
schema,
169-
handler: handler,
170-
// handler: withValidator(schema, handler),
170+
// handler: handler,
171+
handler: withValidator(schema, handler),
171172
}
172173
}
173174

packages/core/src/utils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Column, TableRelationalConfig } from 'drizzle-orm'
22
import { is, Table } from 'drizzle-orm'
33
import type { IsNever, Simplify, ValueOf } from 'type-fest'
4-
import type { ZodError, ZodObject, ZodOptional, ZodType } from 'zod'
4+
import type { ZodIssue, ZodObject, ZodOptional, ZodType } from 'zod'
55

66
import type {
77
ApiHttpStatus,
@@ -125,14 +125,16 @@ export async function validateRequestBody<
125125
TApiRouteSchema extends ApiRouteSchema = any,
126126
TContext extends Record<string, unknown> = Record<string, unknown>,
127127
>(schema: TApiRouteSchema, payload: ApiRouteHandlerPayloadWithContext<TApiRouteSchema, TContext>) {
128-
let zodErrors: Partial<Record<'query' | 'pathParams' | 'headers' | 'body', ZodError>> | undefined
128+
let zodErrors:
129+
| Partial<Record<'query' | 'pathParams' | 'headers' | 'body', ZodIssue[]>>
130+
| undefined
129131

130132
if (schema.query) {
131133
const err = await schema.query.safeParseAsync((payload as any).query)
132134
if (!err.success) {
133135
zodErrors = {
134136
...zodErrors,
135-
query: err.error,
137+
query: err.error.issues,
136138
}
137139
}
138140
}
@@ -142,7 +144,7 @@ export async function validateRequestBody<
142144
if (!err.success) {
143145
zodErrors = {
144146
...zodErrors,
145-
pathParams: err.error,
147+
pathParams: err.error.issues,
146148
}
147149
}
148150
}
@@ -152,7 +154,7 @@ export async function validateRequestBody<
152154
if (!err.success) {
153155
zodErrors = {
154156
...zodErrors,
155-
headers: err.error,
157+
headers: err.error.issues,
156158
}
157159
}
158160
}
@@ -162,7 +164,7 @@ export async function validateRequestBody<
162164
if (!err.success) {
163165
zodErrors = {
164166
...zodErrors,
165-
body: err.error,
167+
body: err.error.issues,
166168
}
167169
}
168170
}

0 commit comments

Comments
 (0)