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

Commit ff276f8

Browse files
committed
update invite code
1 parent 0207d3e commit ff276f8

1 file changed

Lines changed: 60 additions & 27 deletions

File tree

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

Lines changed: 60 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class Service {
6565
return new Promise((resolve , reject ) => {
6666
axios.post(baseUrl+'/auth/api/userdetailsbyemail', {
6767
'email': data.toEmail
68-
}).then(async ((res) => {
68+
}).then((res) => {
6969
userId = res.data.data[0]._id;
7070
previous_packages = res.data.data[0].package;
7171
if(previous_packages == undefined || previous_packages.length == 0){
@@ -103,54 +103,87 @@ class Service {
103103
};
104104
resolve (errorObj);
105105
}
106-
axios.put(baseUrl+'/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': params.headers.authorization } })
107-
.then(async ((result) => {
108-
if (result.data.code == 201) {
109-
let subscription_invite = await (self.subscription_invitation(data, res, params ));
110-
self.sendEmail(data, res, params.headers.authorization);
111-
}
112-
resolve(result.data);
113-
})).catch((err) => {
114-
let errorObj = {};
115-
errorObj.statusText = err.response.statusText;
116-
errorObj.status = err.response.status;
117-
errorObj.data = err.response.data;
118-
resolve (errorObj);
119-
/* eslint-disable no-undef */
120-
});
121-
})).catch((err) => {
106+
// let user = await (self.updateuserdetails(userId,previous_packages,params));
107+
108+
return self.updateuserdetails(userId,previous_packages,params).then(r=>{
109+
return {res:res,userDetail:r}
110+
});
111+
112+
// axios.put(baseUrl+'/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': params.headers.authorization } })
113+
// .then(async ((result) => {
114+
// if (result.data.code == 201) {
115+
// let subscription_invite = await (self.subscription_invitation(data, res, params ));
116+
// self.sendEmail(data, res, params.headers.authorization);
117+
// }
118+
// resolve(result.data);
119+
// })).catch((err) => {
120+
// let errorObj = {};
121+
// errorObj.statusText = err.response.statusText;
122+
// errorObj.status = err.response.status;
123+
// errorObj.data = err.response.data;
124+
// resolve (errorObj);
125+
// /* eslint-disable no-undef */
126+
// });
127+
}).then(result=>{
128+
let userDetailResult=result.userDetail;
129+
let res=result.res;
130+
if (userDetailResult.data.code == 201) {
131+
let subscription_invite = self.subscription_invitation(data, res, params );
132+
self.sendEmail(data, res, params.headers.authorization);
133+
}
134+
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
122141
let errorObj = {};
123-
errorObj.statusText = 'Not Found';
124-
errorObj.status = 404;
125-
errorObj.data = 'No data found with this email ID';
142+
errorObj.statusText = err.response.statusText;
143+
errorObj.status = err.response.status;
144+
errorObj.data = err.response.data;
126145
resolve(errorObj);
127146
});
128147
});
129148
}
149+
150+
updateuserdetails(userId,previous_packages,params){
151+
return axios.put(baseUrl+'/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': params.headers.authorization } })
152+
.then(((result) => {
153+
return result;
154+
})).catch((err) => {
155+
let errorObj = {};
156+
errorObj.statusText = err.response.statusText;
157+
errorObj.status = err.response.status;
158+
errorObj.data = err.response.data;
159+
throw(errorObj);
160+
/* eslint-disable no-undef */
161+
});
162+
}
130163

131164
subscription_invitation(data, res, params) {
132165
let self = this;
133-
this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
166+
return this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
134167
.then(function (response) {
135168
if (response.data.length == 0) {
136-
self.app.service('subscription-invitation').create(data).then(function (response){
169+
return self.app.service('subscription-invitation').create(data).then(function (response){
137170
}).catch(function(err){
138-
return err;
171+
throw(err);
139172
});
140173
} else {
141174
response.data[0].isDeleted = true;
142-
self.app.service('subscription-invitation').patch(response.data[0].id, response.data[0] , '').then(function (response2) {
175+
return self.app.service('subscription-invitation').patch(response.data[0].id, response.data[0] , '').then(function (response2) {
143176
// console.log('response2-----' ,response2);
144177
self.app.service('subscription-invitation').create(data).then(function (response) {
145178
}).catch(function (err) {
146-
return err;
179+
throw(err);
147180
});
148181
}).catch(function (err) {
149-
return err;
182+
throw(err);
150183
});
151184
}
152185
}).catch(function (err) {
153-
return err;
186+
throw(err);
154187
});
155188
}
156189

0 commit comments

Comments
 (0)