2018-01-21 16:26:24 +00:00
|
|
|
angular.module('extension.storidge')
|
2018-02-23 02:10:26 +00:00
|
|
|
.factory('StoridgeProfileService', ['$q', 'Storidge', function StoridgeProfileServiceFactory($q, Storidge) {
|
2018-01-21 16:26:24 +00:00
|
|
|
'use strict';
|
|
|
|
var service = {};
|
|
|
|
|
|
|
|
service.create = function(model) {
|
|
|
|
var payload = new StoridgeCreateProfileRequest(model);
|
2018-02-23 02:10:26 +00:00
|
|
|
return Storidge.createProfile(payload).$promise;
|
2018-01-21 16:26:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
service.update = function(model) {
|
|
|
|
var payload = new StoridgeCreateProfileRequest(model);
|
2018-02-23 02:10:26 +00:00
|
|
|
return Storidge.updateProfile(payload).$promise;
|
2018-01-21 16:26:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
service.delete = function(profileName) {
|
2018-02-23 02:10:26 +00:00
|
|
|
return Storidge.deleteProfile({ id: profileName }).$promise;
|
2018-01-21 16:26:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
service.profile = function(profileName) {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
2018-02-23 02:10:26 +00:00
|
|
|
Storidge.getProfile({ id: profileName }).$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var profile = new StoridgeProfileModel(profileName, data);
|
2018-01-21 16:26:24 +00:00
|
|
|
deferred.resolve(profile);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge profile details', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
service.profiles = function() {
|
|
|
|
var deferred = $q.defer();
|
|
|
|
|
2018-02-23 02:10:26 +00:00
|
|
|
Storidge.queryProfiles().$promise
|
|
|
|
.then(function success(data) {
|
|
|
|
var profiles = data.profiles.map(function (item) {
|
2018-01-21 16:26:24 +00:00
|
|
|
return new StoridgeProfileListModel(item);
|
|
|
|
});
|
|
|
|
deferred.resolve(profiles);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
deferred.reject({ msg: 'Unable to retrieve Storidge profiles', err: err });
|
|
|
|
});
|
|
|
|
|
|
|
|
return deferred.promise;
|
|
|
|
};
|
|
|
|
|
|
|
|
return service;
|
|
|
|
}]);
|