41 lines
1.4 KiB
JavaScript
41 lines
1.4 KiB
JavaScript
"use strict";
|
|
/**
|
|
* Created by viktor.shevchenko on 7/30/2014.
|
|
*/
|
|
(function () {
|
|
'use strict';
|
|
angular.module('myitsmApp')
|
|
.service('followService', ['$resource', function ($resource) {
|
|
var resource = $resource('/smartit/rest/subscription/bulk', {}, {
|
|
follow: {
|
|
method: 'POST',
|
|
isArray: true
|
|
},
|
|
unfollow: {
|
|
url: '/smartit/rest/subscription/bulk/delete',
|
|
method: 'POST',
|
|
isArray: true
|
|
}
|
|
});
|
|
var prepareRequestItems = function (items) {
|
|
var actionItems = _.isArray(items) ? items : [items];
|
|
return _.chain(actionItems)
|
|
.map(function (item) {
|
|
return {
|
|
uuid: item.id || item.uuid,
|
|
type: item.type
|
|
};
|
|
})
|
|
.filter(function (item) {
|
|
return item.uuid && item.type;
|
|
}).value();
|
|
};
|
|
this.follow = function (items) {
|
|
return resource.follow(prepareRequestItems(items)).$promise;
|
|
};
|
|
this.unfollow = function (items) {
|
|
return resource.unfollow(prepareRequestItems(items)).$promise;
|
|
};
|
|
}]);
|
|
}());
|