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 { User } from 'src/common/decorators/user.decorator'
|
||||||
import { NeedAuth } from 'src/common/decorators/need-auth.decorator'
|
import { NeedAuth } from 'src/common/decorators/need-auth.decorator'
|
||||||
import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor'
|
import { PasswordInterceptor } from 'src/common/interceptors/password.interceptor'
|
||||||
|
import { PrismaService } from 'nestjs-prisma'
|
||||||
|
import { UserEntity } from './entities/user.entity'
|
||||||
|
|
||||||
@ApiTags('User')
|
@ApiTags('User')
|
||||||
@Controller('api/users')
|
@Controller('api/users')
|
||||||
export class UsersController {
|
export class UsersController {
|
||||||
constructor(private readonly userService: UsersService) {}
|
constructor(
|
||||||
|
private readonly userService: UsersService,
|
||||||
|
private readonly prismaService: PrismaService,
|
||||||
|
) {}
|
||||||
|
|
||||||
@ApiOperation({ summary: '获取用户信息' })
|
@ApiOperation({ summary: '获取用户信息' })
|
||||||
@UseInterceptors(PasswordInterceptor)
|
@UseInterceptors(PasswordInterceptor)
|
||||||
@NeedAuth()
|
@NeedAuth()
|
||||||
@Get('me')
|
@Get('me')
|
||||||
async getUserInfo(@User('userId') userId: string) {
|
async getUserInfo(@User('userId') userId: string): Promise<UserEntity> {
|
||||||
const user = await this.userService.findUser({ id: userId })
|
return this.prismaService.user.findUniqueOrThrow({ where: { id: userId } })
|
||||||
return user
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,7 @@
|
|||||||
import { Injectable, NotFoundException } from '@nestjs/common'
|
import { Injectable } from '@nestjs/common'
|
||||||
import { PrismaService } from 'nestjs-prisma'
|
import { PrismaService } from 'nestjs-prisma'
|
||||||
import { Prisma } from '@prisma/client'
|
|
||||||
import { UserEntity } from './entities/user.entity'
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
constructor(private prismaService: PrismaService) {}
|
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