33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { Controller, Get, Post, Body, UseInterceptors } from '@nestjs/common'
|
|
import { UsersService } from './users.service'
|
|
import { ApiTags, ApiOperation } 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'
|
|
import { CreateUserDto } from './dto/create-user.dto'
|
|
|
|
@ApiTags('User')
|
|
@Controller('api/users')
|
|
export class UsersController {
|
|
constructor(
|
|
private readonly userService: UsersService,
|
|
private readonly prismaService: PrismaService,
|
|
) {}
|
|
|
|
@ApiOperation({ summary: '获取用户信息' })
|
|
@UseInterceptors(PasswordInterceptor)
|
|
@NeedAuth()
|
|
@Get('me')
|
|
async getUserInfo(@User('userId') userId: string): Promise<UserEntity> {
|
|
return this.prismaService.user.findUniqueOrThrow({ where: { id: userId } })
|
|
}
|
|
|
|
@ApiOperation({ summary: '注册用户' })
|
|
@Post()
|
|
async register(@Body() userData: CreateUserDto) {
|
|
return this.userService.register(userData)
|
|
}
|
|
}
|