nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / services / contact-us / contact-us.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  * Created by robertlo on 10/10/2016.
22  */
23 'use strict';
24
25 (function () {
26     class ContactUsService {
27         constructor($q, $log, $http, conf, uuid) {
28             this.$q = $q;
29             this.$log = $log;
30             this.$http = $http;
31             this.conf = conf;
32             this.uuid = uuid;
33         }
34         getListOfApp() {
35             // this.$log.info('ContactUsService::getListOfavailableApps: get all app list');
36             let deferred = this.$q.defer();
37             // this.$log.info('ContactUsService::getListOfavailableApps: ', this.conf.api.listOfApp);
38             this.$http({
39                 method: "GET",
40                 url: this.conf.api.availableApps,           
41                 cache: false
42             }).then( res => {
43                 // If response comes back as a redirected HTML page which IS NOT a success
44                 // this.$log.info('ContactUsService::getListOfavailableApps availableApps response: ', res);
45                 if (Object.keys(res).length == 0) {
46                     deferred.reject("ContactUsService::getListOfavailableApps: Failed"); 
47                 } else {
48                     // this.$log.debug('ContactUsService::getListOfavailableApps: Succeeded results: ', res);
49                     deferred.resolve(res);
50                 }
51             }).catch( status => {
52                 this.$log.error('ContactUsService::getListOfavailableApps: query error: ',status);
53                 deferred.reject(status);
54             });
55             return deferred.promise;           
56         }
57         
58         getContactUs() {
59             let deferred = this.$q.defer();
60             // this.$log.info('ContactUsService::get all Contact Us list');
61             this.$http({
62                     url: this.conf.api.getContactUS,
63                     method: 'GET',
64                     cache: false,
65                     headers: {
66                         'X-ECOMP-RequestID':this.uuid.generate()
67                     }
68                 }).then(res => {
69                     // If response comes back as a redirected HTML page which IS NOT a success
70                     if (Object.keys(res.data).length == 0) {
71                         deferred.reject("ContactUsService::getContactUs Failed");
72                     } else {
73                         deferred.resolve(res.data);
74                     }
75                 })
76                 .catch(status => {
77                     deferred.reject(status);
78                 });
79             return deferred.promise;
80         }
81         
82         getAppsAndContacts() {
83             let deferred = this.$q.defer();
84             // this.$log.info('ContactUsService::getAppsAndContacts');
85             this.$http({
86                     url: this.conf.api.getAppsAndContacts,
87                     method: 'GET',
88                     cache: false,
89                     headers: {
90                         'X-ECOMP-RequestID':this.uuid.generate()
91                     }
92                 }).then(res => {
93                     // If response comes back as a redirected HTML page which IS NOT a success
94                     if (Object.keys(res.data).length == 0) {
95                         deferred.reject("ContactUsService::getAppsAndContacts Failed");
96                     } else {
97                         deferred.resolve(res.data);
98                     }
99                 })
100                 .catch(status => {
101                     deferred.reject(status);
102                 });
103             return deferred.promise;
104         }
105
106         getContactUSPortalDetails(){
107                 let deferred = this.$q.defer();
108             // this.$log.info('ContactUsService::get all Contact Us Portal Details');
109             this.$http({
110                     url: this.conf.api.getContactUSPortalDetails,
111                     method: 'GET',
112                     cache: false,
113                     headers: {
114                         'X-ECOMP-RequestID':this.uuid.generate()
115                     }
116                 }).then(res => {
117                     // If response comes back as a redirected HTML page which IS NOT a success
118                     if (Object.keys(res.data).length == 0) {
119                         deferred.reject("ContactUsService::getContactUSPortalDetails Failed");
120                     } else {
121                         deferred.resolve(res.data);
122                     }
123                 })
124                 .catch(status => {
125                     deferred.reject(status);
126                 });
127             return deferred.promise;
128         }
129
130         getAppCategoryFunctions(){
131                 let deferred = this.$q.defer();
132             // this.$log.info('ContactUsService::get all App Category Functions');
133             this.$http({
134                     url: this.conf.api.getAppCategoryFunctions,
135                     method: 'GET',
136                     cache: false,
137                     headers: {
138                         'X-ECOMP-RequestID':this.uuid.generate()
139                     }
140                 }).then(res => {
141                     // If response comes back as a redirected HTML page which IS NOT a success
142                     if (Object.keys(res.data).length == 0) {
143                         deferred.reject("ContactUsService::getAppCategoryFunctions Failed");
144                     } else {
145                         deferred.resolve(res.data);
146                     }
147                 })
148                 .catch(status => {
149                     deferred.reject(status);
150                 });
151             return deferred.promise;
152         }
153         
154         addContactUs(newContactUs) {
155                 // this.$log.info('ContactUsService::add a new Contact Us');
156                 // this.$log.info(newContactUs)
157                 let deferred = this.$q.defer();
158             // this.$log.info('ContactUsService:: add Contact Us' + JSON.stringify(newContactUs));
159             
160             var contactUsObj={
161                         appId:newContactUs.app.value,
162                         appName:newContactUs.app.title,
163                         description:newContactUs.desc,
164                         contactName:newContactUs.name,
165                         contactEmail:newContactUs.email,
166                         url:newContactUs.url,                           
167             };
168             this.$http({
169                 url: this.conf.api.saveContactUS,
170                 method: 'POST',
171                 cache: false,
172                 headers: {
173                     'X-ECOMP-RequestID':this.uuid.generate()
174                 },
175                 data: contactUsObj
176             }).then(res => {
177                 // this.$log.info('ContactUsService:: add Contact Us res' ,res);
178                 // If response comes back as a redirected HTML page which IS NOT a success
179                 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
180                     deferred.reject("Add Contact Us failed");
181                     this.$log.error('ContactUsService:: add Contact Us failed');
182                 } else {
183                     deferred.resolve(res.data);
184                 }
185             }).catch(errRes => {
186                    deferred.reject(errRes);
187              });
188             return deferred.promise;
189         }
190         
191         modifyContactUs(contactUsObj) {
192                 // this.$log.info('ContactUsService::edit Contact Us',contactUsObj);            
193                 let deferred = this.$q.defer();
194             this.$http({
195                 url: this.conf.api.saveContactUS,
196                 method: 'POST',
197                 cache: false,
198                 headers: {
199                     'X-ECOMP-RequestID':this.uuid.generate()
200                 },
201                 data: contactUsObj
202             }).then(res => {
203                 // this.$log.info('ContactUsService:: edit Contact Us res' ,res);
204                 // If response comes back as a redirected HTML page which IS NOT a success
205                 if (res==null || Object.keys(res.data).length == 0 || res.data.message == 'failure') {
206                     deferred.reject("Edit Contact Us failed");
207                     this.$log.error('ContactUsService:: edit Contact Us failed');
208                 } else {
209                     deferred.resolve(res.data);
210                 }
211             }).catch(errRes => {
212                    deferred.reject(errRes);
213              });
214             return deferred.promise;
215         }
216
217         removeContactUs(id) {
218             let deferred = this.$q.defer();
219             let url = this.conf.api.deleteContactUS + '/' + id;
220             // this.$log.info('ContactUsService:: remove Contact Us');
221             this.$http({
222                 url: url,
223                 method: 'POST',
224                 cache: false,
225                 data: '',
226                 headers: {
227                     'X-ECOMP-RequestID':this.uuid.generate()
228                 }
229             }).then(res => {
230                 // If response comes back as a redirected HTML page which IS NOT a success
231                 // this.$log.info("ContactUsService::removeContactUs res",res);
232                 deferred.resolve(res.data);
233                 if (Object.keys(res.data).length == 0) {
234                     deferred.reject("ContactUsService::removeContactUs Failed");
235                 } else {
236                     deferred.resolve(res.data);
237                 }
238             }).catch(errRes => {
239                 deferred.reject(errRes);
240             });
241
242             return deferred.promise;
243         }
244     }
245     ContactUsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
246     angular.module('ecompApp').service('contactUsService', ContactUsService)
247 })();