-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
62a4bad
commit 5f20d7d
Showing
14 changed files
with
172 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ObjectType, Field, ID } from '@nestjs/graphql'; | ||
|
||
@ObjectType() | ||
export class User { | ||
@Field(() => ID) | ||
id: number; | ||
|
||
@Field() | ||
username: string; | ||
|
||
@Field() | ||
password: string; | ||
|
||
@Field() | ||
nickname: string; | ||
|
||
@Field() | ||
avatar: string; | ||
|
||
@Field() | ||
thRefreshToken: string; | ||
|
||
@Field() | ||
thAccessToken: string; | ||
|
||
@Field() | ||
email: string; | ||
|
||
@Field() | ||
thId: string; | ||
|
||
@Field(() => [String]) | ||
role: string[]; | ||
|
||
@Field() | ||
createdAt: Date; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { UserResolver } from './user.resolver'; | ||
import { PubSubModule } from 'src/pubsub/pubsub.module'; | ||
import { UserService } from './user.service'; | ||
import { PrismaModule } from 'src/prisma/prisma.module'; | ||
|
||
@Module({ | ||
imports: [PubSubModule, PrismaModule], | ||
providers: [UserResolver, UserService], | ||
exports: [UserService], | ||
}) | ||
export class UserModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { Resolver, Query, Mutation, Args, Subscription } from '@nestjs/graphql'; | ||
import { User } from './user.model'; | ||
import { UseGuards } from '@nestjs/common'; | ||
import { GqlAuthGuard } from '../guards/gql-auth.guard'; | ||
import { GqlUser } from '../decorators/gql-user.decorator'; | ||
import { UserService } from './user.service'; | ||
import { PubSubService } from 'src/pubsub/pubsub.service'; | ||
import { AuthUser } from 'src/types/AuthUser'; | ||
@Resolver(() => User) | ||
export class UserResolver { | ||
constructor( | ||
private readonly userService: UserService, | ||
private readonly pubsub: PubSubService, | ||
) {} | ||
|
||
@Query(() => User, { | ||
description: | ||
"提供执行此查询的用户的详细信息(通过授权 Bearer 标头)", | ||
}) | ||
@UseGuards(GqlAuthGuard) | ||
me(@GqlUser() user: AuthUser) { | ||
return this.userService.convertDbUserToUser(user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { PrismaService } from 'src/prisma/prisma.service'; | ||
import { User } from './user.model'; | ||
import { PubSubService } from 'src/pubsub/pubsub.service'; | ||
import { User as DbUser } from '@prisma/client'; | ||
|
||
@Injectable() | ||
export class UserService { | ||
constructor( | ||
private prisma: PrismaService, | ||
private readonly pubsub: PubSubService, | ||
) {} | ||
/** | ||
* 将 prisma 用户对象转换为用户对象 | ||
* | ||
* @param dbUser Prisma User object | ||
* @returns User object | ||
*/ | ||
convertDbUserToUser(dbUser: DbUser): Promise<User> { | ||
return this.prisma.user.findFirst({ | ||
where:{ | ||
id:dbUser.id | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.