Add full ability to add/delete attendees

This commit is contained in:
2016-12-28 09:25:20 -05:00
parent 49893ffdb6
commit 350a30715a
15 changed files with 292 additions and 28 deletions

View File

@ -2,8 +2,8 @@ var AttendeeConstants = require('../constants/AttendeeConstants');
var ErrorActions = require('./ErrorActions');
var models = require('../models.js');
var Attendee = models.Attendee;
var PopularAttendee = models.PopularAttendee;
var Error = models.Error;
function fetchAttendees() {
@ -32,6 +32,19 @@ function attendeeCreated(attendee) {
}
}
function removeAttendee() {
return {
type: AttendeeConstants.REMOVE_ATTENDEE
}
}
function attendeeRemoved(attendeeId) {
return {
type: AttendeeConstants.ATTENDEE_REMOVED,
attendeeId: attendeeId
}
}
function fetchPopularAttendees() {
return {
type: AttendeeConstants.FETCH_POPULAR_ATTENDEES
@ -114,8 +127,8 @@ function fetchPopular() {
if (e.isError()) {
ErrorActions.serverError(e);
} else {
dispatch(popularAttendeesFetched(data.attendees.map(function(json) {
var a = new Attendee();
dispatch(popularAttendeesFetched(data.popularattendees.map(function(json) {
var a = new PopularAttendee();
a.fromJSON(json);
return a;
})));
@ -128,8 +141,33 @@ function fetchPopular() {
};
}
function remove(attendee) {
return function(dispatch) {
dispatch(removeAttendee());
$.ajax({
type: "DELETE",
dataType: "json",
url: "attendee/"+attendee.AttendeeId+"/",
success: function(data, status, jqXHR) {
var e = new Error();
e.fromJSON(data);
if (e.isError()) {
ErrorActions.serverError(e);
} else {
dispatch(attendeeRemoved(attendee.AttendeeId));
}
},
error: function(jqXHR, status, error) {
ErrorActions.ajaxError(e);
}
});
};
}
module.exports = {
fetchAll: fetchAll,
create: create,
remove: remove,
fetchPopular: fetchPopular
};