Skip to content

Instantly share code, notes, and snippets.

@rskhan167
Last active October 13, 2021 15:38
Show Gist options
  • Select an option

  • Save rskhan167/475888e3f060d053cca512d28771d8bf to your computer and use it in GitHub Desktop.

Select an option

Save rskhan167/475888e3f060d053cca512d28771d8bf to your computer and use it in GitHub Desktop.

Revisions

  1. rskhan167 revised this gist Oct 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion user.controller.ts
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@ export class UserController {
    }

    @Post()
    @ApiOkResponse({ status: 200, type: User })
    @ApiOkResponse({ status: 201, type: User })
    async create(@Body() createUserDto: CreateUserDto): Promise<User> {
    return await this.userService.create(createUserDto);
    }
  2. rskhan167 revised this gist Oct 13, 2021. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion user.controller.ts
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ export class UserController {
    constructor(private readonly userService: UserService) {}

    @Get('all')
    @ApiOkResponse({ status: 200, type: [User] })
    @ApiOkResponse({ status: 200, type: User, isArray: true })
    async getAll(): Promise<User[]> {
    return this.userService.getAll();
    }
  3. rskhan167 created this gist Oct 13, 2021.
    29 changes: 29 additions & 0 deletions user.controller.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    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] })
    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: 200, type: User })
    async create(@Body() createUserDto: CreateUserDto): Promise<User> {
    return await this.userService.create(createUserDto);
    }
    }