Просмотр исходного кода

♻️ refactor(clients): remove custom client list route

- 删除src/server/api/clients/get.ts文件中的自定义客户列表路由实现
- 移除index.ts中对customListRoute的导入引用,简化路由结构
yourname 8 месяцев назад
Родитель
Сommit
dd73c6dfde
2 измененных файлов с 0 добавлено и 147 удалено
  1. 0 146
      src/server/api/clients/get.ts
  2. 0 1
      src/server/api/clients/index.ts

+ 0 - 146
src/server/api/clients/get.ts

@@ -1,146 +0,0 @@
-import { OpenAPIHono, createRoute } from '@hono/zod-openapi';
-import { z } from '@hono/zod-openapi';
-import { ClientSchema } from '@/server/modules/clients/client.entity';
-import { ClientService } from '@/server/modules/clients/client.service';
-import { authMiddleware } from '@/server/middleware/auth.middleware';
-import { AppDataSource } from '@/server/data-source';
-import { AuthContext } from '@/server/types/context';
-
-const app = new OpenAPIHono<AuthContext>();
-
-// 查询参数Schema
-const ListQuery = z.object({
-  page: z.coerce.number().int().positive().default(1),
-  pageSize: z.coerce.number().int().positive().default(10),
-  keyword: z.string().optional(),
-  auditStatus: z.coerce.number().min(0).max(2).optional(),
-  status: z.coerce.number().min(0).max(1).optional(),
-  responsibleUserId: z.coerce.number().int().positive().optional(),
-  salesPersonId: z.coerce.number().int().positive().optional(),
-  operatorId: z.coerce.number().int().positive().optional(),
-  customerType: z.string().optional(),
-  industry: z.string().optional(),
-  source: z.string().optional(),
-  startDateFrom: z.coerce.date().optional(),
-  startDateTo: z.coerce.date().optional(),
-  createdAtFrom: z.coerce.date().optional(),
-  createdAtTo: z.coerce.date().optional(),
-  sortBy: z.enum([
-    'id', 'companyName', 'contactPerson', 'createdAt', 'updatedAt', 
-    'startDate', 'nextContactTime', 'auditStatus', 'status'
-  ]).default('createdAt'),
-  sortOrder: z.enum(['ASC', 'DESC']).default('DESC')
-});
-
-// 响应Schema
-const ListResponse = z.object({
-  data: z.array(ClientSchema),
-  pagination: z.object({
-    total: z.number(),
-    current: z.number(),
-    pageSize: z.number()
-  })
-});
-
-// 路由定义
-const route = createRoute({
-  method: 'get',
-  path: '/',
-  middleware: [authMiddleware],
-  request: {
-    query: ListQuery
-  },
-  responses: {
-    200: {
-      description: '成功获取客户列表',
-      content: {
-        'application/json': {
-          schema: ListResponse
-        }
-      }
-    }
-  }
-});
-
-// 路由实现
-app.openapi(route, async (c) => {
-  try {
-    const query = c.req.valid('query');
-    const service = new ClientService(AppDataSource);
-    
-    // 构建where条件
-    const where: any = {};
-    
-    if (query.auditStatus !== undefined) {
-      where.auditStatus = query.auditStatus;
-    }
-    if (query.status !== undefined) {
-      where.status = query.status;
-    }
-    if (query.responsibleUserId !== undefined) {
-      where.responsibleUserId = query.responsibleUserId;
-    }
-    if (query.salesPersonId !== undefined) {
-      where.salesPersonId = query.salesPersonId;
-    }
-    if (query.operatorId !== undefined) {
-      where.operatorId = query.operatorId;
-    }
-    if (query.customerType) {
-      where.customerType = query.customerType;
-    }
-    if (query.industry) {
-      where.industry = query.industry;
-    }
-    if (query.source) {
-      where.source = query.source;
-    }
-    
-    // 构建日期范围
-    if (query.startDateFrom || query.startDateTo) {
-      where.startDateRange = {
-        start: query.startDateFrom,
-        end: query.startDateTo
-      };
-    }
-    
-    if (query.createdAtFrom || query.createdAtTo) {
-      where.createdAtRange = {
-        start: query.createdAtFrom,
-        end: query.createdAtTo
-      };
-    }
-    
-    // 构建排序对象
-    const order: any = {};
-    order[query.sortBy] = query.sortOrder;
-    
-    // 调用自定义的getList方法
-    const [data, total] = await service.getList(
-      query.page,
-      query.pageSize,
-      query.keyword,
-      ['companyName', 'contactPerson', 'mobile'],
-      where,
-      ['responsibleUser', 'salesPerson', 'operator'],
-      order
-    );
-    
-    return c.json({
-      data,
-      pagination: {
-        total,
-        current: query.page,
-        pageSize: query.pageSize
-      }
-    });
-  } catch (error) {
-    console.error('获取客户列表失败:', error);
-    return c.json({ 
-      code: 500, 
-      message: error instanceof Error ? error.message : '获取列表失败' 
-    }, 500);
-  }
-});
-
-export default app;

+ 0 - 1
src/server/api/clients/index.ts

@@ -3,7 +3,6 @@ import { createCrudRoutes } from '@/server/utils/generic-crud.routes';
 import { Client } from '@/server/modules/clients/client.entity';
 import { ClientSchema, CreateClientDto, UpdateClientDto } from '@/server/modules/clients/client.entity';
 import { authMiddleware } from '@/server/middleware/auth.middleware';
-import customListRoute from './get'; // 自定义的get路由
 
 // 创建通用CRUD路由
 const clientRoutes = createCrudRoutes({