nest-project/src/users/users.controller.ts

26 lines
954 B
TypeScript
Raw Normal View History

2023-02-17 16:13:04 +08:00
import { Controller, Get, UseInterceptors } from '@nestjs/common'
2023-02-15 20:32:14 +08:00
import { UsersService } from './users.service'
2023-02-20 16:25:46 +08:00
import { ApiOperation, ApiTags } from '@nestjs/swagger'
2023-02-17 14:21:08 +08:00
import { User } from 'src/common/decorators/user.decorator'
import { NeedAuth } from 'src/common/decorators/need-auth.decorator'
2023-02-17 16:13:04 +08:00
import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor'
2023-02-22 09:42:47 +08:00
import { PrismaService } from 'nestjs-prisma'
import { UserEntity } from './entities/user.entity'
2023-02-15 20:32:14 +08:00
2023-02-17 14:21:08 +08:00
@ApiTags('User')
2023-02-20 16:25:46 +08:00
@Controller('api/users')
2023-02-15 20:32:14 +08:00
export class UsersController {
2023-02-22 09:42:47 +08:00
constructor(
private readonly userService: UsersService,
private readonly prismaService: PrismaService,
) {}
2023-02-17 14:21:08 +08:00
2023-02-20 16:25:46 +08:00
@ApiOperation({ summary: '获取用户信息' })
2023-02-17 16:13:04 +08:00
@UseInterceptors(PasswordInterceptor)
2023-02-17 14:21:08 +08:00
@NeedAuth()
2023-02-20 16:25:46 +08:00
@Get('me')
2023-02-22 09:42:47 +08:00
async getUserInfo(@User('userId') userId: string): Promise<UserEntity> {
return this.prismaService.user.findUniqueOrThrow({ where: { id: userId } })
2023-02-17 14:21:08 +08:00
}
2023-02-15 20:32:14 +08:00
}