Bläddra i källkod

🔧 chore(api): remove silver-talents-admin manual routes and adjust index.ts

- delete silver-talents-admin/[id]/delete.ts route file
- delete silver-talents-admin/[id]/get.ts route file
- delete silver-talents-admin/[id]/patch.ts route file
- delete silver-talents-admin/[id]/put.ts route file
- delete silver-talents-admin/get.ts route file
- adjust route registration order in index.ts: statsRoute first, then crudRoutes
yourname 7 månader sedan
förälder
incheckning
bb3b1df16f

+ 0 - 57
src/server/api/silver-talents-admin/[id]/delete.ts

@@ -1,57 +0,0 @@
-import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
-import { z } from '@hono/zod-openapi';
-import { ErrorSchema } from '@/server/utils/errorHandler';
-import { AppDataSource } from '@/server/data-source';
-import { SilverTalentAdminService } from '@/server/modules/silver-users/silver-talent-admin.service';
-import { AuthContext } from '@/server/types/context';
-import { authMiddleware } from '@/server/middleware/auth.middleware';
-
-// 路径参数Schema
-const GetParams = z.object({
-  id: z.coerce.number().int().positive().openapi({
-    param: { name: 'id', in: 'path' },
-    example: 1,
-    description: '人才ID'
-  })
-});
-
-// 路由定义
-const routeDef = createRoute({
-  method: 'delete',
-  path: '/{id}',
-  middleware: [authMiddleware],
-  request: {
-    params: GetParams
-  },
-  responses: {
-    200: {
-      description: '删除成功',
-      content: { 'application/json': { schema: z.object({ success: z.boolean() }) } }
-    },
-    404: {
-      description: '人才信息不存在',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    500: {
-      description: '服务器错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    }
-  }
-});
-
-const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
-  try {
-    const { id } = c.req.valid('param');
-    const service = new SilverTalentAdminService(AppDataSource);
-    
-    await service.delete(id);
-    
-    return c.json({ success: true }, 200);
-  } catch (error) {
-    const message = error instanceof Error ? error.message : '删除失败';
-    const code = message === '未找到该银龄人才信息' ? 404 : 500;
-    return c.json({ code, message }, code);
-  }
-});
-
-export default app;

+ 0 - 63
src/server/api/silver-talents-admin/[id]/get.ts

@@ -1,63 +0,0 @@
-import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
-import { z } from '@hono/zod-openapi';
-import { SilverUserProfileSchema } from '@/server/modules/silver-users/silver-user-profile.entity';
-import { ErrorSchema } from '@/server/utils/errorHandler';
-import { AppDataSource } from '@/server/data-source';
-import { SilverTalentAdminService } from '@/server/modules/silver-users/silver-talent-admin.service';
-import { AuthContext } from '@/server/types/context';
-import { authMiddleware } from '@/server/middleware/auth.middleware';
-
-// 路径参数Schema
-const GetParams = z.object({
-  id: z.coerce.number().int().positive().openapi({
-    param: { name: 'id', in: 'path' },
-    example: 1,
-    description: '人才ID'
-  })
-});
-
-// 路由定义
-const routeDef = createRoute({
-  method: 'get',
-  path: '/{id}',
-  middleware: [authMiddleware],
-  request: {
-    params: GetParams
-  },
-  responses: {
-    200: {
-      description: '成功获取银龄人才详情',
-      content: { 'application/json': { schema: SilverUserProfileSchema } }
-    },
-    400: {
-      description: '请求参数错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    404: {
-      description: '人才信息不存在',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    500: {
-      description: '服务器错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    }
-  }
-});
-
-// 路由实现
-const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
-  try {
-    const { id } = c.req.valid('param');
-    const service = new SilverTalentAdminService(AppDataSource);
-    
-    const talent = await service.findByIdForAdmin(id);
-    
-    return c.json(talent, 200);
-  } catch (error) {
-    const message = error instanceof Error ? error.message : '获取详情失败';
-    const code = message === '未找到该银龄人才信息' ? 404 : 500;
-    return c.json({ code, message }, code);
-  }
-});
-
-export default app;

+ 0 - 88
src/server/api/silver-talents-admin/[id]/patch.ts

@@ -1,88 +0,0 @@
-import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
-import { z } from '@hono/zod-openapi';
-import { SilverUserProfileSchema } from '@/server/modules/silver-users/silver-user-profile.entity';
-import { ErrorSchema } from '@/server/utils/errorHandler';
-import { AppDataSource } from '@/server/data-source';
-import { SilverTalentAdminService } from '@/server/modules/silver-users/silver-talent-admin.service';
-import { AuthContext } from '@/server/types/context';
-import { authMiddleware } from '@/server/middleware/auth.middleware';
-import { CertificationStatus } from '@/server/modules/silver-users/silver-user-profile.entity';
-
-// 路径参数Schema
-const GetParams = z.object({
-  id: z.coerce.number().int().positive().openapi({
-    param: { name: 'id', in: 'path' },
-    example: 1,
-    description: '人才ID'
-  })
-});
-
-// 请求体Schema
-const UpdateCertificationDto = z.object({
-  certificationStatus: z.coerce.number().int().min(0).max(3).openapi({
-    description: '认证状态:0-未认证,1-认证中,2-已认证,3-已拒绝',
-    example: 2
-  }),
-  certificationInfo: z.string().max(2000).optional().openapi({
-    description: '认证信息',
-    example: '高级教师职称证书、工作经验证明'
-  })
-});
-
-// 路由定义
-const routeDef = createRoute({
-  method: 'patch',
-  path: '/{id}/certification',
-  middleware: [authMiddleware],
-  request: {
-    params: GetParams,
-    body: {
-      content: {
-        'application/json': { schema: UpdateCertificationDto }
-      }
-    }
-  },
-  responses: {
-    200: {
-      description: '认证状态更新成功',
-      content: { 'application/json': { schema: SilverUserProfileSchema } }
-    },
-    400: {
-      description: '请求参数错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    404: {
-      description: '人才信息不存在',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    500: {
-      description: '服务器错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    }
-  }
-});
-
-// 路由实现
-const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
-  try {
-    const { id } = c.req.valid('param');
-    const body = await c.req.json();
-    const user = c.get('user');
-    const service = new SilverTalentAdminService(AppDataSource);
-    
-    const talent = await service.updateCertificationStatus(
-      id,
-      body.certificationStatus as CertificationStatus,
-      body.certificationInfo,
-      user.id
-    );
-    
-    return c.json(talent, 200);
-  } catch (error) {
-    const message = error instanceof Error ? error.message : '更新认证状态失败';
-    const code = message === '未找到该银龄人才信息' ? 404 : 500;
-    return c.json({ code, message }, code);
-  }
-});
-
-export default app;

+ 0 - 69
src/server/api/silver-talents-admin/[id]/put.ts

@@ -1,69 +0,0 @@
-import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
-import { z } from '@hono/zod-openapi';
-import { UpdateSilverUserProfileDto } from '@/server/modules/silver-users/silver-user-profile.entity';
-import { ErrorSchema } from '@/server/utils/errorHandler';
-import { AppDataSource } from '@/server/data-source';
-import { SilverTalentAdminService } from '@/server/modules/silver-users/silver-talent-admin.service';
-import { AuthContext } from '@/server/types/context';
-import { authMiddleware } from '@/server/middleware/auth.middleware';
-
-// 路径参数Schema
-const GetParams = z.object({
-  id: z.coerce.number().int().positive().openapi({
-    param: { name: 'id', in: 'path' },
-    example: 1,
-    description: '人才ID'
-  })
-});
-
-// 路由定义
-const routeDef = createRoute({
-  method: 'put',
-  path: '/{id}',
-  middleware: [authMiddleware],
-  request: {
-    params: GetParams,
-    body: {
-      content: {
-        'application/json': { schema: UpdateSilverUserProfileDto }
-      }
-    }
-  },
-  responses: {
-    200: {
-      description: '人才信息更新成功',
-      content: { 'application/json': { schema: UpdateSilverUserProfileDto } }
-    },
-    400: {
-      description: '请求参数错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    404: {
-      description: '人才信息不存在',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    500: {
-      description: '服务器错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    }
-  }
-});
-
-const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
-  try {
-    const { id } = c.req.valid('param');
-    const body = await c.req.json();
-    const user = c.get('user');
-    const service = new SilverTalentAdminService(AppDataSource);
-    
-    const updatedTalent = await service.updateByAdmin(id, body, user.id);
-    
-    return c.json(updatedTalent, 200);
-  } catch (error) {
-    const message = error instanceof Error ? error.message : '更新失败';
-    const code = message === '未找到该银龄人才信息' ? 404 : 500;
-    return c.json({ code, message }, code);
-  }
-});
-
-export default app;

+ 0 - 126
src/server/api/silver-talents-admin/get.ts

@@ -1,126 +0,0 @@
-import { createRoute, OpenAPIHono } from '@hono/zod-openapi';
-import { z } from '@hono/zod-openapi';
-import { SilverUserProfileSchema } from '@/server/modules/silver-users/silver-user-profile.entity';
-import { ErrorSchema } from '@/server/utils/errorHandler';
-import { AppDataSource } from '@/server/data-source';
-import { SilverTalentAdminService } from '@/server/modules/silver-users/silver-talent-admin.service';
-import { AuthContext } from '@/server/types/context';
-import { authMiddleware } from '@/server/middleware/auth.middleware';
-import { CertificationStatus, JobSeekingStatus } from '@/server/modules/silver-users/silver-user-profile.entity';
-
-// 查询参数Schema
-const AdminListQuery = z.object({
-  page: z.coerce.number().int().min(1).default(1).openapi({
-    description: '页码',
-    example: 1
-  }),
-  pageSize: z.coerce.number().int().min(1).max(100).default(20).openapi({
-    description: '每页数量',
-    example: 20
-  }),
-  keyword: z.string().optional().openapi({
-    description: '搜索关键词',
-    example: '张'
-  }),
-  certificationStatus: z.coerce.number().int().min(0).max(3).optional().openapi({
-    description: '认证状态:0-未认证,1-认证中,2-已认证,3-已拒绝',
-    example: 2
-  }),
-  jobSeekingStatus: z.coerce.number().int().min(0).max(2).optional().openapi({
-    description: '求职状态:0-未求职,1-积极求职,2-观望机会',
-    example: 1
-  }),
-  ageMin: z.coerce.number().int().min(50).max(100).optional().openapi({
-    description: '最小年龄',
-    example: 50
-  }),
-  ageMax: z.coerce.number().int().min(50).max(100).optional().openapi({
-    description: '最大年龄',
-    example: 80
-  }),
-  sortBy: z.enum(['createdAt', 'age', 'realName', 'certificationStatus', 'totalPoints', 'knowledgeRankingScore'])
-    .default('createdAt').openapi({
-      description: '排序字段'
-    }),
-  sortOrder: z.enum(['ASC', 'DESC']).default('DESC').openapi({
-    description: '排序方向'
-  })
-});
-
-// 响应Schema
-const AdminListResponse = z.object({
-  data: z.array(SilverUserProfileSchema),
-  pagination: z.object({
-    total: z.number().openapi({ example: 100, description: '总记录数' }),
-    current: z.number().openapi({ example: 1, description: '当前页码' }),
-    pageSize: z.number().openapi({ example: 20, description: '每页数量' }),
-    totalPages: z.number().openapi({ example: 5, description: '总页数' })
-  }),
-  stats: z.object({
-    totalCount: z.number().openapi({ example: 1000, description: '总人才数' }),
-    certifiedCount: z.number().openapi({ example: 800, description: '已认证数' }),
-    pendingCount: z.number().openapi({ example: 100, description: '认证中数' }),
-    rejectedCount: z.number().openapi({ example: 50, description: '已拒绝数' }),
-    unCertifiedCount: z.number().openapi({ example: 50, description: '未认证数' })
-  })
-});
-
-// 路由定义
-const routeDef = createRoute({
-  method: 'get',
-  path: '/',
-  middleware: [authMiddleware],
-  request: {
-    query: AdminListQuery
-  },
-  responses: {
-    200: {
-      description: '成功获取银龄人才列表',
-      content: { 'application/json': { schema: AdminListResponse } }
-    },
-    400: {
-      description: '请求参数错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    },
-    500: {
-      description: '服务器错误',
-      content: { 'application/json': { schema: ErrorSchema } }
-    }
-  }
-});
-
-// 路由实现
-const app = new OpenAPIHono<AuthContext>().openapi(routeDef, async (c) => {
-  try {
-    const query = c.req.valid('query');
-    const service = new SilverTalentAdminService(AppDataSource);
-    
-    const [data, total, stats] = await service.findForAdmin({
-      keyword: query.keyword,
-      certificationStatus: query.certificationStatus !== undefined ? query.certificationStatus as CertificationStatus : undefined,
-      jobSeekingStatus: query.jobSeekingStatus !== undefined ? query.jobSeekingStatus as JobSeekingStatus : undefined,
-      ageMin: query.ageMin,
-      ageMax: query.ageMax,
-      sortBy: query.sortBy,
-      sortOrder: query.sortOrder,
-      page: query.page,
-      pageSize: query.pageSize
-    });
-
-    return c.json({
-      data,
-      pagination: {
-        total,
-        current: query.page,
-        pageSize: query.pageSize,
-        totalPages: Math.ceil(total / query.pageSize)
-      },
-      stats
-    }, 200);
-  } catch (error) {
-    const message = error instanceof Error ? error.message : '获取列表失败';
-    return c.json({ code: 500, message }, 500);
-  }
-});
-
-export default app;

+ 1 - 1
src/server/api/silver-talents-admin/index.ts

@@ -27,7 +27,7 @@ const crudRoutes = createCrudRoutes({
 
 // 创建应用并组合路由
 const app = new OpenAPIHono()
+  .route('/', statsRoute)
   .route('/', crudRoutes)
-  .route('/', statsRoute);
 
 export default app;