Skip to content

Instantly share code, notes, and snippets.

@rskhan167
Last active October 13, 2021 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rskhan167/475888e3f060d053cca512d28771d8bf to your computer and use it in GitHub Desktop.
Save rskhan167/475888e3f060d053cca512d28771d8bf to your computer and use it in GitHub Desktop.
Nestjs Series - Part 3
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