Last active
October 13, 2021 15:38
-
-
Save rskhan167/475888e3f060d053cca512d28771d8bf to your computer and use it in GitHub Desktop.
Nestjs Series - Part 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Post, Body, Get, Param } from '@nestjs/common'; | |
import { ApiOkResponse } from '@nestjs/swagger'; | |
import { CreateUserDto } from './dtos/create-user.dto'; | |
import { UserService } from './user.service'; | |
import { User } from './entities/user.entity'; | |
@Controller('user') | |
export class UserController { | |
constructor(private readonly userService: UserService) {} | |
@Get('all') | |
@ApiOkResponse({ status: 200, type: User, isArray: true }) | |
async getAll(): Promise<User[]> { | |
return this.userService.getAll(); | |
} | |
@Get(':userId') | |
@ApiOkResponse({ status: 200, type: User }) | |
async getUser(@Param('userId') userId: number): Promise<User> { | |
return await this.userService.getUser(userId); | |
} | |
@Post() | |
@ApiOkResponse({ status: 201, type: User }) | |
async create(@Body() createUserDto: CreateUserDto): Promise<User> { | |
return await this.userService.create(createUserDto); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment