From b0a77ab82860351638f8c11813cde20beace5a68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Allen=20Zhang=20=28=E5=BC=A0=E6=B6=9B=29?= Date: Mon, 5 Feb 2024 17:04:54 +0800 Subject: [PATCH] feat: add user info api --- .../canyon-backend/src/user/user.controller.ts | 17 +++++++++++++++++ packages/canyon-backend/src/user/user.module.ts | 4 +++- .../src/Report/components/IstanbulReport.tsx | 1 + packages/canyon-report/src/main.tsx | 16 +++++++++------- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100755 packages/canyon-backend/src/user/user.controller.ts diff --git a/packages/canyon-backend/src/user/user.controller.ts b/packages/canyon-backend/src/user/user.controller.ts new file mode 100755 index 00000000..18697dd9 --- /dev/null +++ b/packages/canyon-backend/src/user/user.controller.ts @@ -0,0 +1,17 @@ +import { Controller, Get, UseGuards, Request } from '@nestjs/common'; +import { PrismaService } from '../prisma/prisma.service'; +import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard'; + +@Controller() +export class UserController { + constructor(private readonly prismaService: PrismaService) {} + @UseGuards(JwtAuthGuard) + @Get('/api/user') + getHello(@Request() req): Promise { + return this.prismaService.user.findFirst({ + where: { + id: req.user.id, + }, + }); + } +} diff --git a/packages/canyon-backend/src/user/user.module.ts b/packages/canyon-backend/src/user/user.module.ts index 6e9aeb9b..9c3e0ffc 100755 --- a/packages/canyon-backend/src/user/user.module.ts +++ b/packages/canyon-backend/src/user/user.module.ts @@ -1,10 +1,12 @@ import { Module } from '@nestjs/common'; import { UserResolver } from './user.resolver'; import { UserService } from './user.service'; -import { PrismaModule } from 'src/prisma/prisma.module' +import { PrismaModule } from 'src/prisma/prisma.module'; +import { UserController } from './user.controller'; @Module({ imports: [PrismaModule], + controllers: [UserController], providers: [UserResolver, UserService], exports: [UserService], }) diff --git a/packages/canyon-report/src/Report/components/IstanbulReport.tsx b/packages/canyon-report/src/Report/components/IstanbulReport.tsx index a09d1413..5c3987ac 100755 --- a/packages/canyon-report/src/Report/components/IstanbulReport.tsx +++ b/packages/canyon-report/src/Report/components/IstanbulReport.tsx @@ -157,6 +157,7 @@ const IstanbulReport: FC = ({ /> ) )} + {loading &&
loading...
} ); }; diff --git a/packages/canyon-report/src/main.tsx b/packages/canyon-report/src/main.tsx index 31438193..9457b872 100755 --- a/packages/canyon-report/src/main.tsx +++ b/packages/canyon-report/src/main.tsx @@ -19,13 +19,15 @@ function getDecode(str: string) { const report = init(document.querySelector('#root') as any, { onSelectFile(path: string) { return new Promise((resolve) => { - resolve({ - // @ts-ignore - fileCoverage: __coverage__[path], - // @ts-ignore - fileContent: getDecode(__filecontent__[path]), - fileCodeChange:[1,2,3,4] - }); + setTimeout(()=>{ + resolve({ + // @ts-ignore + fileCoverage: __coverage__[path], + // @ts-ignore + fileContent: getDecode(__filecontent__[path]), + fileCodeChange:[1,2,3,4] + }); + },1000) }); }, });