-
-
Save consoledotblog/45c24cb9fed72ea9031d to your computer and use it in GitHub Desktop.
Building Applications with TypeScript - Snippet 13
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
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