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

新增获取团队列表的服务、控制器和路由,支持管理员通过接口获取所有团队信息。

wuyi 4 месяцев назад
Родитель
Сommit
a479b01c7f
3 измененных файлов с 22 добавлено и 0 удалено
  1. 9 0
      src/controllers/team.controller.ts
  2. 7 0
      src/routes/team.routes.ts
  3. 6 0
      src/services/team.service.ts

+ 9 - 0
src/controllers/team.controller.ts

@@ -112,4 +112,13 @@ export class TeamController {
       return reply.code(500).send({ message: '获取统计数据失败', error })
     }
   }
+
+  async getTeams(request: FastifyRequest, reply: FastifyReply) {
+    try {
+      const teams = await this.teamService.getTeams()
+      return reply.send(teams)
+    } catch (error) {
+      return reply.code(500).send({ message: '获取团队失败', error })
+    }
+  }
 }

+ 7 - 0
src/routes/team.routes.ts

@@ -62,4 +62,11 @@ export default async function teamRoutes(fastify: FastifyInstance) {
     { onRequest: [authenticate, hasRole(UserRole.ADMIN)] },
     teamController.getStatistics.bind(teamController)
   )
+
+  // 获取团队
+  fastify.get(
+    '/all',
+    { onRequest: [authenticate, hasRole(UserRole.ADMIN)] },
+    teamController.getTeams.bind(teamController)
+  )
 }

+ 6 - 0
src/services/team.service.ts

@@ -133,4 +133,10 @@ export class TeamService {
 
     return statistics
   }
+
+  async getTeams(): Promise<Array<{ id: number; name: string; userId: number }>> {
+    return await this.teamRepository.find({
+      select: ['id', 'name', 'userId']
+    })
+  }
 }