4 class BasicAuthAccountService {
5 constructor($q, $log, $http, conf,uuid, utilsService) {
11 this.utilsService = utilsService;
14 createAccount(newAccount) {
15 let deferred = this.$q.defer();
18 url: this.conf.api.basicAuthAccount,
22 'X-ECOMP-RequestID':this.uuid.generate()
25 if (res == null || res.data == null) {
26 this.$log.error('BasicAuthAccountService::createAccount Failed: Result or result.data is null');
27 deferred.reject("BasicAuthAccountService::createAccount Failed: Result or result.data is null");
28 } else if (!this.utilsService.isValidJSON(res.data)) {
29 this.$log.error('BasicAuthAccountService::createAccount Failed: Invalid JSON format');
30 deferred.reject("BasicAuthAccountService::createAccount Failed: Invalid JSON format");
32 deferred.resolve(res.data);
36 deferred.reject(errRes);
38 return deferred.promise;
41 updateAccount(accountId, newAccount) {
42 let deferred = this.$q.defer();
45 url: this.conf.api.basicAuthAccount + "/" + accountId,
49 'X-ECOMP-RequestID':this.uuid.generate()
52 if (res == null || res.data == null) {
53 this.$log.error('BasicAuthAccountService::updateAccount Failed: Result or result.data is null');
54 deferred.reject("BasicAuthAccountService::updateAccount Failed: Result or result.data is null");
55 } else if (!this.utilsService.isValidJSON(res.data)) {
56 this.$log.error('BasicAuthAccountService::updateAccount Failed: Invalid JSON format');
57 deferred.reject("BasicAuthAccountService::updateAccount Failed: Invalid JSON format");
59 deferred.resolve(res.data);
63 deferred.reject(errRes);
65 return deferred.promise;
69 let deferred = this.$q.defer();
72 url: this.conf.api.basicAuthAccount,
75 'X-ECOMP-RequestID':this.uuid.generate()
78 if (res == null || res.data == null) {
79 this.$log.error('BasicAuthAccountService::getAccountList Failed: Result or result.data is null');
80 deferred.reject("BasicAuthAccountService::getAccountList Failed: Result or result.data is null");
81 } else if (!this.utilsService.isValidJSON(res.data)) {
82 this.$log.error('BasicAuthAccountService::getAccountList Failed: Invalid JSON format');
83 deferred.reject("BasicAuthAccountService::getAccountList Failed: Invalid JSON format");
85 deferred.resolve(res.data.response);
89 deferred.reject(errRes);
91 return deferred.promise;
94 deleteAccount(accountId) {
95 let deferred = this.$q.defer();
98 url: this.conf.api.basicAuthAccount + "/" + accountId,
101 'X-ECOMP-RequestID':this.uuid.generate()
104 if (res == null || res.data == null) {
105 this.$log.error('BasicAuthAccountService::deleteAccount Failed: Result or result.data is null');
106 deferred.reject("BasicAuthAccountService::deleteAccount Failed: Result or result.data is null");
107 } else if (!this.utilsService.isValidJSON(res.data)) {
108 this.$log.error('BasicAuthAccountService::deleteAccount Failed: Invalid JSON format');
109 deferred.reject("BasicAuthAccountService::deleteAccount Failed: Invalid JSON format");
111 deferred.resolve(res.data);
115 deferred.reject(errRes);
117 return deferred.promise;
122 BasicAuthAccountService.$inject = ['$q', '$log', '$http', 'conf','uuid4', 'utilsService'];
123 angular.module('ecompApp').service('basicAuthAccountService', BasicAuthAccountService)