|
@@ -63,7 +63,7 @@ constructor() {
|
|
|
```typescript
|
|
```typescript
|
|
|
import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
|
|
import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
|
|
|
import { YourEntity } from '@/server/modules/your-module/your-entity.entity';
|
|
import { YourEntity } from '@/server/modules/your-module/your-entity.entity';
|
|
|
-import { YourEntitySchema, CreateYourEntityDto, UpdateYourEntityDto } from '@/server/modules/your-module/your-entity.entity';
|
|
|
|
|
|
|
+import { YourEntitySchema, CreateYourEntityDto, UpdateYourEntityDto } from '@/server/modules/your-module/your-entity.schema';
|
|
|
import { authMiddleware } from '@/server/middleware/auth.middleware';
|
|
import { authMiddleware } from '@/server/middleware/auth.middleware';
|
|
|
|
|
|
|
|
const yourEntityRoutes = createCrudRoutes({
|
|
const yourEntityRoutes = createCrudRoutes({
|
|
@@ -133,7 +133,6 @@ api.route('/api/v1/your-entities', yourEntityRoutes);
|
|
|
```typescript
|
|
```typescript
|
|
|
// your-entity.entity.ts
|
|
// your-entity.entity.ts
|
|
|
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from 'typeorm';
|
|
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne, OneToMany } from 'typeorm';
|
|
|
-import { z } from '@hono/zod-openapi';
|
|
|
|
|
import { RelatedEntity } from './related-entity.entity';
|
|
import { RelatedEntity } from './related-entity.entity';
|
|
|
|
|
|
|
|
@Entity('your_entity')
|
|
@Entity('your_entity')
|
|
@@ -150,6 +149,8 @@ export class YourEntity {
|
|
|
// 其他字段...
|
|
// 其他字段...
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+// your-entity.schema.ts
|
|
|
|
|
+import { z } from '@hono/zod-openapi';
|
|
|
// Zod schemas
|
|
// Zod schemas
|
|
|
export const YourEntitySchema = z.object({
|
|
export const YourEntitySchema = z.object({
|
|
|
id: z.number().int().positive().openapi({ description: '实体ID' }),
|
|
id: z.number().int().positive().openapi({ description: '实体ID' }),
|
|
@@ -179,7 +180,8 @@ export const UpdateYourEntityDto = z.object({
|
|
|
|
|
|
|
|
```typescript
|
|
```typescript
|
|
|
import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
|
|
import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
|
|
|
-import { PolicyNews, PolicyNewsSchema, CreatePolicyNewsDto, UpdatePolicyNewsDto } from '@/server/modules/silver-users/policy-news.entity';
|
|
|
|
|
|
|
+import { PolicyNews } from '@/server/modules/silver-users/policy-news.entity';
|
|
|
|
|
+import { PolicyNewsSchema, CreatePolicyNewsDto, UpdatePolicyNewsDto } from '@/server/modules/silver-users/policy-news.schema';
|
|
|
import { File } from '@/server/modules/files/file.entity';
|
|
import { File } from '@/server/modules/files/file.entity';
|
|
|
import { authMiddleware } from '@/server/middleware/auth.middleware';
|
|
import { authMiddleware } from '@/server/middleware/auth.middleware';
|
|
|
|
|
|
|
@@ -350,4 +352,4 @@ export class YourEntityService extends GenericCrudService<YourEntity> {
|
|
|
5. **搜索优化**:合理设置`searchFields`,避免在大表的文本字段上进行模糊搜索
|
|
5. **搜索优化**:合理设置`searchFields`,避免在大表的文本字段上进行模糊搜索
|
|
|
6. **分页处理**:所有列表接口必须支持分页,避免返回大量数据
|
|
6. **分页处理**:所有列表接口必须支持分页,避免返回大量数据
|
|
|
7. **关联查询**:使用`relations`配置时,避免过度关联导致性能问题
|
|
7. **关联查询**:使用`relations`配置时,避免过度关联导致性能问题
|
|
|
-8. **事务管理**:复杂操作应使用事务确保数据一致性
|
|
|
|
|
|
|
+8. **事务管理**:复杂操作应使用事务确保数据一致性
|