2 * ================================================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ================================================================================
21 * Created by robertlo on 10/10/2016.
26 class ContactUsService {
27 constructor($q, $log, $http, conf, uuid) {
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);
40 url: this.conf.api.availableApps,
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");
48 // this.$log.debug('ContactUsService::getListOfavailableApps: Succeeded results: ', res);
49 deferred.resolve(res);
52 this.$log.error('ContactUsService::getListOfavailableApps: query error: ',status);
53 deferred.reject(status);
55 return deferred.promise;
59 let deferred = this.$q.defer();
60 // this.$log.info('ContactUsService::get all Contact Us list');
62 url: this.conf.api.getContactUS,
66 'X-ECOMP-RequestID':this.uuid.generate()
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");
73 deferred.resolve(res.data);
77 deferred.reject(status);
79 return deferred.promise;
82 getAppsAndContacts() {
83 let deferred = this.$q.defer();
84 // this.$log.info('ContactUsService::getAppsAndContacts');
86 url: this.conf.api.getAppsAndContacts,
90 'X-ECOMP-RequestID':this.uuid.generate()
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");
97 deferred.resolve(res.data);
101 deferred.reject(status);
103 return deferred.promise;
106 getContactUSPortalDetails(){
107 let deferred = this.$q.defer();
108 // this.$log.info('ContactUsService::get all Contact Us Portal Details');
110 url: this.conf.api.getContactUSPortalDetails,
114 'X-ECOMP-RequestID':this.uuid.generate()
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");
121 deferred.resolve(res.data);
125 deferred.reject(status);
127 return deferred.promise;
130 getAppCategoryFunctions(){
131 let deferred = this.$q.defer();
132 // this.$log.info('ContactUsService::get all App Category Functions');
134 url: this.conf.api.getAppCategoryFunctions,
138 'X-ECOMP-RequestID':this.uuid.generate()
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");
145 deferred.resolve(res.data);
149 deferred.reject(status);
151 return deferred.promise;
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));
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,
169 url: this.conf.api.saveContactUS,
173 'X-ECOMP-RequestID':this.uuid.generate()
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');
183 deferred.resolve(res.data);
186 deferred.reject(errRes);
188 return deferred.promise;
191 modifyContactUs(contactUsObj) {
192 // this.$log.info('ContactUsService::edit Contact Us',contactUsObj);
193 let deferred = this.$q.defer();
195 url: this.conf.api.saveContactUS,
199 'X-ECOMP-RequestID':this.uuid.generate()
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');
209 deferred.resolve(res.data);
212 deferred.reject(errRes);
214 return deferred.promise;
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');
227 'X-ECOMP-RequestID':this.uuid.generate()
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");
236 deferred.resolve(res.data);
239 deferred.reject(errRes);
242 return deferred.promise;
245 ContactUsService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
246 angular.module('ecompApp').service('contactUsService', ContactUsService)