Created
December 2, 2015 03:31
-
-
Save Nijhazer/eeb5bd1ce6fdefedb155 to your computer and use it in GitHub Desktop.
Building Applications with TypeScript - Snippet 13
This file contains 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
var router = Express.Router(); | |
var taskManager = new DataManager( | |
new MongoDataDriver(EnvDataConfig.getInstance()), | |
Task | |
); | |
var taskController = new ExpressController(); | |
taskController.manager = taskManager; | |
router.route(Task.API_BASE_URL) | |
.get(taskController.findAll()) | |
.post(taskController.create()); | |
export class ExpressController implements IExpressController { | |
public _manager: IDataManager; | |
public set manager(manager : IDataManager) { | |
this._manager = manager; | |
} | |
public findAll() { | |
var manager = this._manager; | |
return (request: Express.Request, response: Express.Response) => { | |
manager.findAll().then((results) => { | |
response.send(results); | |
}, (error) => { | |
console.error(error, 'error occurred when searching for documents'); | |
response.send(error); | |
}); | |
}; | |
} | |
public create() { | |
// truncated for brevity | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment