nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / services / portal-admins / portal-admins.service.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ================================================================================
19  */
20
21 'use strict';
22
23 (function () {
24     class PortalAdminsService {
25         constructor($q, $log, $http, conf, uuid) {
26             this.$q = $q;
27             this.$log = $log;
28             this.$http = $http;
29             this.conf = conf;
30             this.uuid = uuid;
31         }
32
33         getPortalAdmins() {
34             let deferred = this.$q.defer();
35             this.$log.info('PortalAdminsService::get all portal admins list');
36             this.$http({
37                     url: this.conf.api.portalAdmins,
38                     method: 'GET',
39                     cache: false,
40                     headers: {
41                         'X-ECOMP-RequestID':this.uuid.generate()
42                     }
43                 }).then(res => {
44                     if (Object.keys(res.data).length == 0) {
45                         deferred.reject("PortalAdminsService::getPortalAdmins Failed");
46                     } else {
47                         deferred.resolve(res.data);
48                     }
49                 })
50                 .catch(status => {
51                     deferred.reject(status);
52                 });
53             return deferred.promise;
54         }
55
56         addPortalAdmin(userData) {
57             let deferred = this.$q.defer();
58             this.$log.info('PortalAdminsService:: add Portal Admin' + JSON.stringify(userData));
59             this.$http({
60                 url: this.conf.api.portalAdmin,
61                 method: 'POST',
62                 cache: false,
63                 headers: {
64                     'X-ECOMP-RequestID':this.uuid.generate()
65                 },
66                 data: userData
67             }).then(res => {
68                 if (Object.keys(res.data).length == 0) {
69                     deferred.reject("PortalAdminsService::addPortalAdmin Failed");
70                 } else {
71                     deferred.resolve(res.data);
72                 }
73             })
74                 .catch(errRes => {
75                     deferred.reject(errRes);
76                 });
77             return deferred.promise;
78         }
79
80         removePortalAdmin(userId) {
81             let deferred = this.$q.defer();
82             let url = this.conf.api.portalAdmin + '/' + userId;
83             this.$log.info('PortalAdminsService:: remove Portal Admin');
84             this.$http({
85                 url: url,
86                 method: 'DELETE',
87                 cache: false,
88                 data: '',
89                 headers: {
90                     'X-ECOMP-RequestID':this.uuid.generate()
91                 }
92             }).then(res => {
93                 if (Object.keys(res.data).length == 0) {
94                     deferred.reject("PortalAdminsService::removePortalAdmin Failed");
95                 } else {
96                     deferred.resolve(res.data);
97                 }
98             }).catch(errRes => {
99                 deferred.reject(errRes);
100             });
101
102             return deferred.promise;
103         }
104     }
105     PortalAdminsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
106     angular.module('ecompApp').service('portalAdminsService', PortalAdminsService)
107 })();