eventman/angular_app/js/services.js

82 lines
2.7 KiB
JavaScript
Raw Normal View History

2015-03-22 08:57:57 +01:00
'use strict';
2015-03-22 09:36:32 +01:00
/* Services that are used to interact with the backend. */
2015-03-21 13:21:15 +01:00
var eventManServices = angular.module('eventManServices', ['ngResource']);
2015-04-05 00:55:59 +02:00
eventManServices.factory('Attendee', ['$resource', 'Event',
function($resource, Event) {
return $resource('events/:id/persons/:person_id', {id: '@_id', person_id: '@person_id'}, {
personAttended: {
method: 'PUT',
params: {'persons.$.attended': true},
transformResponse: function(data, headers) {
console.log('reply');
console.log(angular.fromJson(data));
return angular.fromJson(data).event;
}
}
});
}]
);
2015-03-22 09:19:30 +01:00
2015-03-21 13:21:15 +01:00
eventManServices.factory('Event', ['$resource',
2015-03-21 15:45:40 +01:00
function($resource) {
2015-04-05 00:55:59 +02:00
return $resource('events/:id', {id: '@_id', person_id: '@person_id'}, {
2015-03-21 15:45:40 +01:00
all: {
method: 'GET',
isArray: true,
transformResponse: function(data, headers) {
return angular.fromJson(data).events;
}
},
2015-03-23 23:06:44 +01:00
get: {method: 'GET',
transformResponse: function(data, headers) {
data = angular.fromJson(data);
if (data && data['begin-datetime']) {
data['begin-datetime'] = data['begin-datetime'].getTime();
}
if (data && data['end-datetime']) {
data['end-datetime'] = data['end-datetime'].getTime();
}
return data;
}
},
2015-04-05 00:55:59 +02:00
update: {method: 'PUT'},
personAttended: {
method: 'PUT',
isArray: true,
url: 'events/:id/persons/:person_id',
transformResponse: function(data, headers) {
return angular.fromJson(data).event.persons;
}
}
2015-03-21 15:45:40 +01:00
});
}]
2015-03-21 13:21:15 +01:00
);
eventManServices.factory('Person', ['$resource',
2015-03-21 15:45:40 +01:00
function($resource) {
2015-03-21 20:31:36 +01:00
return $resource('persons/:id', {id: '@_id'}, {
2015-03-21 15:45:40 +01:00
all: {
method: 'GET',
2015-03-21 20:31:36 +01:00
isArray: true,
2015-03-21 15:45:40 +01:00
transformResponse: function(data, headers) {
return angular.fromJson(data).persons;
}
2015-03-21 16:48:00 +01:00
},
2015-04-04 14:15:52 +02:00
update: {method: 'PUT'},
getEvents: {
method: 'GET',
url: 'persons/:id/events',
isArray: true,
transformResponse: function(data, headers) {
return angular.fromJson(data).events;
}
}
2015-03-21 15:45:40 +01:00
});
}]
2015-03-21 13:21:15 +01:00
);