Browse Source

📝 docs(entity): 优化实体和Schema的导入位置说明

- 将zod导入从实体示例移至Schema示例中,符合实际使用场景
- 明确区分实体类(.entity.ts)和Zod Schema(.schema.ts)的文件位置和职责
- 调整文档结构,使实体创建步骤更加清晰
yourname 3 tháng trước cách đây
mục cha
commit
fcdfbc4c75
2 tập tin đã thay đổi với 11 bổ sung3 xóa
  1. 1 1
      .roo/rules/10-entity.md
  2. 10 2
      .roo/rules/11-custom-crud.md

+ 1 - 1
.roo/rules/10-entity.md

@@ -28,7 +28,6 @@
 
 ```typescript
 import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
-import { z } from '@hono/zod-openapi';
 
 @Entity('table_name') // 使用小写下划线命名表名
 export class EntityName {
@@ -107,6 +106,7 @@ updatedAt!: Date;
 ### 7.1 基础类型规范
 
 ```typescript
+import { z } from '@hono/zod-openapi';
 export const EntitySchema = z.object({
   id: z.number().int().positive().openapi({ description: 'ID说明' }),
   // 字符串字段

+ 10 - 2
.roo/rules/11-custom-crud.md

@@ -12,11 +12,10 @@
 
 ### 1. **创建实体**
    - 位置: `src/server/modules/[模块名]/[实体名].entity.ts`
-   - 定义实体类和Zod Schema
+   - 定义实体类
    - 示例:
      ```typescript
      import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
-     import { z } from '@hono/zod-openapi';
      
      @Entity('your_entity')
      export class YourEntity {
@@ -28,6 +27,14 @@
        
        // 其他业务字段...
      }
+     ```
+
+
+   - 位置: `src/server/modules/[模块名]/[实体名].schema.ts`
+   - 定义实体Zod Schema
+   - 示例:
+     ```typescript
+     import { z } from '@hono/zod-openapi';
      
      // Zod Schema定义
      export const YourEntitySchema = z.object({
@@ -47,6 +54,7 @@
      });
      ```
 
+
 ### 2. **注册实体到数据源**
    - 在`src/server/data-source.ts`中添加实体导入和注册:
      ```typescript