Skip to content

Instantly share code, notes, and snippets.

@hakant
Last active March 19, 2017 12:02
Show Gist options
  • Save hakant/85fbfa3f3d77f82c2b17457a96356d09 to your computer and use it in GitHub Desktop.
Save hakant/85fbfa3f3d77f82c2b17457a96356d09 to your computer and use it in GitHub Desktop.
router.get('/', catchAsyncErrors(async function (req, res, next) {
var request = new GetIdeasRequest();
request.user = req.user;
var response = await application.ExecuteAsync<GetIdeasRequest, GetIdeasResponse>(request);
res.json(response.ideas);
}));
router.post("/add", catchAsyncErrors(async function (req, res, next) {
var request = new InsertIdeaRequest();
request.user = req.user;
request.idea = <IIdea>req.body;
await application.ExecuteAsync<InsertIdeaRequest, InsertIdeaResponse>(request);
res.sendStatus(200);
}));
router.post("/edit-title", catchAsyncErrors(async function (req, res, next) {
var request = new EditIdeaRequest();
request.user = req.user;
request.idea = <IIdea>req.body;
request.mode = EditMode.Title;
await application.ExecuteAsync<EditIdeaRequest, EditIdeaResponse>(request);
res.sendStatus(200);
}));
router.post("/edit-overview", catchAsyncErrors(async function (req, res, next) {
var request = new EditIdeaRequest();
request.user = req.user;
request.idea = <IIdea>req.body;
request.mode = EditMode.Overview;
await application.ExecuteAsync<EditIdeaRequest, EditIdeaResponse>(request);
res.sendStatus(200);
}));
router.post("/edit-description", catchAsyncErrors(async function (req, res, next) {
var request = new EditIdeaRequest();
request.user = req.user;
request.idea = <IIdea>req.body;
request.mode = EditMode.Description;
await application.ExecuteAsync<EditIdeaRequest, EditIdeaResponse>(request);
res.sendStatus(200);
}));
router.post("/like", catchAsyncErrors(async function (req, res, next) {
var request = new ToggleIdeaLikeRequest();
request.user = req.user;
request.ideaId = req.body.ideaId
await application.ExecuteAsync<ToggleIdeaLikeRequest, ToggleIdeaLikeResponse>(request);
res.sendStatus(200);
}));
router.post("/join", catchAsyncErrors(async function (req, res, next) {
var request = new JoinIdeaRequest();
request.user = req.user;
request.ideaId = req.body.ideaId
await application.ExecuteAsync<JoinIdeaRequest, JoinIdeaResponse>(request);
res.sendStatus(200);
}));
router.post("/unjoin", catchAsyncErrors(async function (req, res, next) {
var request = new LeaveIdeaRequest();
request.user = req.user;
request.ideaId = req.body.ideaId
await application.ExecuteAsync<LeaveIdeaRequest, LeaveIdeaResponse>(request);
res.sendStatus(200);
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment