update users module
This commit is contained in:
parent
085deabc7f
commit
dfa91f8e7a
@ -4,18 +4,22 @@ import { ApiOperation, ApiTags } from '@nestjs/swagger'
|
||||
import { User } from 'src/common/decorators/user.decorator'
|
||||
import { NeedAuth } from 'src/common/decorators/need-auth.decorator'
|
||||
import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor'
|
||||
import { PrismaService } from 'nestjs-prisma'
|
||||
import { UserEntity } from './entities/user.entity'
|
||||
|
||||
@ApiTags('User')
|
||||
@Controller('api/users')
|
||||
export class UsersController {
|
||||
constructor(private readonly userService: UsersService) {}
|
||||
constructor(
|
||||
private readonly userService: UsersService,
|
||||
private readonly prismaService: PrismaService,
|
||||
) {}
|
||||
|
||||
@ApiOperation({ summary: '获取用户信息' })
|
||||
@UseInterceptors(PasswordInterceptor)
|
||||
@NeedAuth()
|
||||
@Get('me')
|
||||
async getUserInfo(@User('userId') userId: string) {
|
||||
const user = await this.userService.findUser({ id: userId })
|
||||
return user
|
||||
async getUserInfo(@User('userId') userId: string): Promise<UserEntity> {
|
||||
return this.prismaService.user.findUniqueOrThrow({ where: { id: userId } })
|
||||
}
|
||||
}
|
||||
|
@ -1,19 +1,7 @@
|
||||
import { Injectable, NotFoundException } from '@nestjs/common'
|
||||
import { Injectable } from '@nestjs/common'
|
||||
import { PrismaService } from 'nestjs-prisma'
|
||||
import { Prisma } from '@prisma/client'
|
||||
import { UserEntity } from './entities/user.entity'
|
||||
|
||||
@Injectable()
|
||||
export class UsersService {
|
||||
constructor(private prismaService: PrismaService) {}
|
||||
|
||||
async findUser(where: Prisma.UserWhereUniqueInput): Promise<UserEntity> {
|
||||
const user = await this.prismaService.user.findUnique({
|
||||
where,
|
||||
})
|
||||
if (!user) {
|
||||
throw new NotFoundException(`No user found`)
|
||||
}
|
||||
return user
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user