|
|
@@ -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;
|