Created
May 15, 2017 14:21
-
-
Save wtrocki/0a53c3441674da3026ff2341ce863853 to your computer and use it in GitHub Desktop.
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 {Get, Post, Route, Body, Query, Header, Path, SuccessResponse, Controller } from 'tsoa'; | |
import {UserService} from '../services/userService'; | |
import {User, UserCreationRequest} from '../models/user'; | |
@Route('Users') | |
export class UsersController extends Controller { | |
@Get('{id}') | |
public async getUser(id: number, @Query() name: string): Promise<User> { | |
return await new UserService().get(id); | |
} | |
@SuccessResponse('201', 'Created') // Custom success response | |
@Post() | |
public async createUser(@Body() requestBody: UserCreationRequest): Promise<void> { | |
new UserService().create(request); | |
this.setStatus(201); // set return status 201 | |
return Promise.resolve(); | |
} | |
@Get('{id}') | |
public async getPrivateUser(@Path('id') ID: number, @Header('Authorization') authorization: string): Promise<User> { | |
return new UserService().get(id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment