Skip to content
This repository was archived by the owner on Oct 30, 2023. It is now read-only.

Commit f90795a

Browse files
committed
update invite with axios call
1 parent 81e487f commit f90795a

1 file changed

Lines changed: 29 additions & 16 deletions

File tree

service/src/services/invite/invite.class.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,28 @@ class Service {
124124
// resolve (errorObj);
125125
// /* eslint-disable no-undef */
126126
// });
127-
}).then(result=>{
127+
}).then(async ((result)=>{
128128
let userDetailResult=result.userDetail;
129129
let res=result.res;
130+
console.log('userDetailResult::::', userDetailResult) // eslint-disable-line
130131
if (userDetailResult.data.code == 201) {
131-
let subscription_invite = self.subscription_invitation(data, res, params );
132+
console.log('201::::', userDetailResult) // eslint-disable-line
133+
let subscription_invite = await (self.subscription_invitation(data, res, params ));
132134
self.sendEmail(data, res, params.headers.authorization);
133135
}
134136
resolve(userDetailResult.data);
135-
}).catch((err) => {
136-
// let errorObj = {};
137-
// errorObj.statusText = 'Not Found';
138-
// errorObj.status = 404;
139-
// errorObj.data = 'No data found with this email ID';
140-
console.log('Invite Create Catch:: ', err) // eslint-disable-line
137+
})).catch((err) => {
141138
let errorObj = {};
142-
errorObj.statusText = err.response.statusText;
143-
errorObj.status = err.response.status;
144-
errorObj.data = err.response.data;
139+
console.log('Invite Create Catch:: ', err) // eslint-disable-line
140+
if (err.response.data === 'data not found!') {
141+
errorObj.statusText = 'Not Found';
142+
errorObj.status = 404;
143+
errorObj.data = 'No data found with this email ID';
144+
} else {
145+
errorObj.statusText = err.response.statusText;
146+
errorObj.status = err.response.status;
147+
errorObj.data = err.response.data;
148+
}
145149
resolve(errorObj);
146150
});
147151
});
@@ -163,16 +167,24 @@ class Service {
163167

164168
subscription_invitation(data, res, params) {
165169
let self = this;
166-
return this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
170+
console.log('subscription_invitation::: ') // eslint-disable-line
171+
// return this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
172+
// return axios.get(baseUrl+'/subscription/subscription-invitation', {query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
173+
return axios({
174+
method: 'get',
175+
url: baseUrl+'/subscription/subscription-invitation?toEmail='+data.toEmail+'&subscriptionId='+data.subscriptionId+'&isDeleted=false',
176+
headers: { 'Authorization': params.headers.authorization }
177+
})
167178
.then(function (response) {
168-
if (response.data.length == 0) {
179+
console.log('response::', response) // eslint-disable-line
180+
if (response.data.data.length == 0) {
169181
return self.app.service('subscription-invitation').create(data).then(function (response){
170182
}).catch(function(err){
171183
throw(err);
172184
});
173185
} else {
174-
response.data[0].isDeleted = true;
175-
return self.app.service('subscription-invitation').patch(response.data[0].id, response.data[0] , '').then(function (response2) {
186+
response.data.data[0].isDeleted = true;
187+
return self.app.service('subscription-invitation').patch(response.data.data[0].id, response.data.data[0] , '').then(function (response2) {
176188
// console.log('response2-----' ,response2);
177189
self.app.service('subscription-invitation').create(data).then(function (response) {
178190
}).catch(function (err) {
@@ -183,6 +195,7 @@ class Service {
183195
});
184196
}
185197
}).catch(function (err) {
198+
console.log('ERROR::', err) // eslint-disable-line
186199
throw(err);
187200
});
188201
}
@@ -192,7 +205,7 @@ class Service {
192205
SendEmailBody = SendEmailBody.replace(/DOMAIN/g, 'https://www.dashboard.' + domainKey);
193206
SendEmailBody = SendEmailBody.replace(/SYSTEMNAME/g, Object.keys(data.role)[0]);
194207
SendEmailBody = SendEmailBody.replace(/ROLE/g, Object.values(data.role)[0]);
195-
208+
console.log('subscription_invitation::: ') // eslint-disable-line
196209
axios({ method: 'post',
197210
url: baseUrl+'/vmailmicro/sendEmail',
198211
headers: {'Authorization': authToken},

0 commit comments

Comments
 (0)