Skip to content

Instantly share code, notes, and snippets.

@BramKaashoek
Last active Sep 21, 2017
Embed
What would you like to do?
//...
this.create = function(meeting, successHandler, errorHandler) {
this.meetingsCol.create(meeting, {
contentType: 'application/json',
headers: { Authorization: sessionStorage.getItem('token')},
success: function(model, response) {
successHandler(response);
},
error: errorHandler
});
};
this.fetch = function(id, successHandler, errorHandler) {
var meeting = meetingModel();
meeting.id = id;
meeting.fetch({
success: function(model, response) {
var meetingData = oj.KnockoutUtils.map(meeting);
successHandler(meetingData);
},
error: errorHandler
});
};
this.fetchAll = function(succesHandler, errorHandler) {
this.meetingsCol.fetch({
success: function(collection, response) {
succesHandler(response.data);
},
error: errorHandler
});
};
this.update = function(updatedMeeting, successHandler, errorHandler) {
var jsUpdatedMeeting = ko.toJS(updatedMeeting);
var meeting = meetingModel()
meeting.save(jsUpdatedMeeting, {
contentType: 'application/json',
headers: { Authorization: sessionStorage.getItem('token')},
success: successHandler,
error: errorHandler
});
};
this.delete = function(id, successHandler, errorHandler) {
var meeting = meetingModel()
meeting.id = id
meeting.destroy({
headers: { Authorization: sessionStorage.getItem('token')},
success: function() {
this.meetingsCol.remove(meeting);
successHandler;
},
error: errorHandler
});
};
}
return new MeetingsService();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment