Răsfoiți Sursa

fix(goods-category): 修复商品分类API验证错误,允许id=0

修改 GoodsCategorySchema 的 id 字段验证规则,从 .positive() 改为 .nonnegative(),
以支持数据库中 id=0 的默认分类记录。

问题:查询 /api/v1/admin/goods-categories 时返回 400 错误,
错误信息 "Too small: expected number to be >0"。

原因:之前创建了 id=0 的默认分类记录用于外键约束,但 schema 验证要求 id > 0。

🤖 Generated with [Claude Code](https://claude.ai/code)
via [Happy](https://happy.engineering)

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Happy <yesreply@happy.engineering>
yourname 1 lună în urmă
părinte
comite
0d0cf7fcb3

+ 1 - 1
packages/goods-module-mt/src/schemas/goods-category.schema.mt.ts

@@ -2,7 +2,7 @@ import { z } from '@hono/zod-openapi';
 import { FileSchema } from '@d8d/file-module-mt/schemas';
 
 export const GoodsCategorySchema = z.object({
-  id: z.number().int().positive().openapi({ description: '类别ID' }),
+  id: z.number().int().nonnegative('类别ID必须为非负数').openapi({ description: '类别ID' }),
   name: z.string().min(1, '类别名称不能为空').max(255, '类别名称最多255个字符').openapi({
     description: '类别名称',
     example: '电子产品'