Skip to content

Commit 9fd9016

Browse files
Merge pull request CoderDojo#170 from CoderDojo/staging
Release from staging
2 parents 49ef283 + 0ce04b5 commit 9fd9016

File tree

5 files changed

+52
-9
lines changed

5 files changed

+52
-9
lines changed

config/perm/events.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ module.exports = function () {
133133
}],
134134
'loadTicket': [{
135135
role: 'basic-user'
136-
}]
136+
}],
137+
'applications': {
138+
'list': {
139+
role: 'basic-user'
140+
}
141+
}
137142
};
138143
};

lib/bulk-apply-applications.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,22 @@ function bulkApplyApplications (args, callback) {
105105

106106
function saveApplications (done) {
107107
async.map(applications, function (application, cb) {
108-
if (!updateAction) {
109-
ensureApplicationIsUnique(cb);
110-
} else {
111-
saveApplication(cb);
112-
}
108+
// You cannot have multiple applications in the same ticket
109+
// NOTE : faulty on bulk apply as front-end allows it (async creation, ticket doesn't exists yet)
110+
ensureApplicationIsUnique(cb);
113111

112+
// Ensure the id of the application is prefilled when the same ticket is booked
113+
// Shoudln't be necessary if enforced by API
114114
function ensureApplicationIsUnique (cb) {
115-
seneca.act({role: plugin, cmd: 'searchApplications', query: {sessionId: application.sessionId, userId: application.userId}}, function (err, applications) {
115+
seneca.act({role: plugin, cmd: 'searchApplications',
116+
query: {sessionId: application.sessionId, userId: application.userId, deleted: false, status: {ne$: 'cancelled'}}},
117+
function (err, applications) {
116118
if (err) return cb(err);
117119
if (applications.length > 0) {
118120
var ticketFound = _.find(applications, function (applicationFound) {
119-
return applicationFound.ticketId === application.ticketId && !applicationFound.deleted;
121+
return applicationFound.ticketId === application.ticketId;
120122
});
121-
if (ticketFound) return cb();
123+
if (ticketFound) application.id = ticketFound.id;
122124
}
123125
return saveApplication(cb);
124126
});

lib/cd-events.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ module.exports = function () {
5858
// CRUD
5959
seneca.add({role: plugin, entity: 'invite', cmd: 'list'}, require('./entity/invite/list'));
6060

61+
// Controllers
62+
seneca.add({role: plugin, ctrl: 'applications', cmd: 'list'}, require('./controllers/application/list'));
63+
6164
// PERMS
6265
seneca.add({role: plugin, cmd: 'is_ticketing_admin'}, isTicketingAdmin.bind(seneca));
6366
// TODO : those 2 perms are very alike, need for a factory ?

lib/controllers/application/list.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Load user's (and its children) applications for an event
3+
* @param {Object} args {user, eventId}
4+
* @return {[Applications]} List of applications
5+
*/
6+
module.exports = function (args, done) {
7+
var seneca = this;
8+
var role = args.role;
9+
var eventId = args.eventId;
10+
var user = args.user;
11+
// TODO : extend to allow selection of profile
12+
// TODO : extend to allow selection of status/deletion ?
13+
seneca.act({role: 'cd-profiles', cmd: 'load_user_profile', userId: user.id},
14+
function (err, profile) {
15+
if (err) return done(err);
16+
var children = profile.children || [];
17+
var userIds = children.concat(user.id);
18+
seneca.act({role: role, cmd: 'searchApplications', query: {userId: { in$: userIds }, eventId: eventId, deleted: 0, status: {ne$: 'cancelled'}}},
19+
function (err, applications) {
20+
if (err) return done(err);
21+
done(null, applications);
22+
});
23+
});
24+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DO $$
2+
BEGIN
3+
BEGIN
4+
ALTER TABLE cd_events ADD UNIQUE (eventbrite_id);
5+
EXCEPTION
6+
WHEN OTHERS THEN RAISE NOTICE 'constraint eventbrite_id already exists in cd_events.';
7+
END;
8+
END;
9+
$$

0 commit comments

Comments
 (0)