Skip to content

Commit

Permalink
Implement server-side action signup
Browse files Browse the repository at this point in the history
Fixes #205
  • Loading branch information
richardolsson committed Jul 4, 2018
1 parent 2d96b45 commit 3c84f79
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/common
49 changes: 49 additions & 0 deletions src/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,55 @@ export default function initApp(messages) {

app.use(preloader(messages));

app.get('*', (req, res, next) => {
if (req.query.actionSignup) {
const [ orgId, actionId, op ] = req.query.actionSignup.split('/');

if (orgId && actionId && op) {
let fragment = '';

req.z.resource('orgs', orgId, 'actions', actionId)
.get()
.then(result => {
const actionData = result.data.data;
fragment = (new Date(actionData.start_time)).format('{yyyy}-{MM}-{dd}');

// Find user personId from list of memberships
const membershipList = req.store.getState().getIn(['orgs', 'membershipList']);
const membership = membershipList.get('items').find(val => (
val.getIn(['organization', 'id']) == orgId));
const personId = membership.getIn(['profile', 'id']);

const resource = req.z.resource('orgs', orgId, 'actions', actionId,
'responses', personId);

return (op == 'signup')? resource.put() : resource.del();
})
.then(() => {
res.redirect(307, url.format({
protocol: req.protocol,
host: req.get('host'),
pathname: req.path,
hash: fragment,
}));
})
.catch(err => {
res.redirect(307, url.format({
protocol: req.protocol,
host: req.get('host'),
pathname: req.path,
}));
});
}
else {
next();
}
}
else {
next();
}
});

// Prefer slug over ID for org pages
app.get('/o/:orgId', (req, res, next) => {
let org = organization(req.store.getState(), req.params.orgId);
Expand Down

0 comments on commit 3c84f79

Please sign in to comment.