Last active
May 17, 2016 07:43
-
-
Save pleerock/7b149cbcebb7fa7455b3083c027f70bb 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 {Request, Response} from "express"; | |
import {JsonController, Get, Post, Put, Patch, Delete} from "routing-controllers"; | |
@JsonController() | |
export class BlogController { | |
@Get("/blogs") | |
getAll() { | |
return this.createPromise([ | |
{ id: 1, name: "Blog 1!"}, | |
{ id: 2, name: "Blog 2!"}, | |
], 2000); | |
} | |
@Get("/blogs/:id") | |
getOne(@Req() request: Request) { | |
return this.createPromise({ id: request.params.id, name: "Blog"}, 2000); | |
} | |
/** | |
* Creates a fake promise with timeout. | |
*/ | |
private createPromise(data: any, timeout: number): Promise<any> { | |
return new Promise<any>((ok, fail) => { | |
setTimeout(() => ok(data), timeout); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment