import { Body , ClassSerializerInterceptor , Controller , Delete , Get , NotFoundException , Param , Post , Put , UseGuards , UseInterceptors , } from '@nestjs/common' ; import { User } from './user.entity' ; import { UserService } from './user.service' ; import { CreateUserDto } from './dto/create-user.dto' ; import { EntityId } from 'typeorm/repository/EntityId' ; import { plainToClass } from 'class-transformer' ; import { UpdateUserDto } from './dto/update-user.dto' ; import { DeleteResult } from 'typeorm/index' ; import { JwtAuthGuard } from '../auth/guards/jwt-auth.guard' ; @ UseInterceptors ( ClassSerializerInterceptor ) @ Controller ( 'users' ) @ UseGuards ( JwtAuthGuard ) export class UserController { constructor ( private readonly userService ) { } @ Get ( ) index ( ) { return this . userService . index ( ) ; } @ Get ( '/inactive' ) getInactiveUser ( ) { return this . userService . getInactiveUsers ( ) ; } @ Get ( '/:id' ) async show ( @ Param ( 'id' ) id ) { const user = await this . userService . findById ( id ) ; if ( ! user ) { throw new NotFoundException ( ) ; } return user ; } @ Post ( ) async create ( @ Body ( ) userData ) { const createdUser = await this . userService . store ( userData ) ; return plainToClass ( User , createdUser ) ; } @ Put ( '/:id' ) update ( @ Param ( 'id' ) id , @ Body ( ) userData ) { return this . userService . update ( id , userData ) ; } @ Delete ( '/:id' ) destroy ( @ Param ( 'id' ) id ) { return this . userService . delete ( id ) ; } }