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

Commit 0207d3e

Browse files
committed
update invite route for subscription invite issue
1 parent 8f1ca1a commit 0207d3e

2 files changed

Lines changed: 20 additions & 31 deletions

File tree

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class Service {
106106
axios.put(baseUrl+'/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': params.headers.authorization } })
107107
.then(async ((result) => {
108108
if (result.data.code == 201) {
109-
let subscription_invite = await (self.subscription_invitation(data , res ));
109+
let subscription_invite = await (self.subscription_invitation(data, res, params ));
110110
self.sendEmail(data, res, params.headers.authorization);
111111
}
112112
resolve(result.data);
@@ -126,21 +126,18 @@ class Service {
126126
resolve(errorObj);
127127
});
128128
});
129-
130-
131129
}
132130

133-
subscription_invitation(data, res) {
131+
subscription_invitation(data, res, params) {
134132
let self = this;
135-
this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }})
133+
this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
136134
.then(function (response) {
137135
if (response.data.length == 0) {
138136
self.app.service('subscription-invitation').create(data).then(function (response){
139137
}).catch(function(err){
140138
return err;
141139
});
142140
} else {
143-
// console.log(response.data);
144141
response.data[0].isDeleted = true;
145142
self.app.service('subscription-invitation').patch(response.data[0].id, response.data[0] , '').then(function (response2) {
146143
// console.log('response2-----' ,response2);
@@ -151,17 +148,12 @@ class Service {
151148
}).catch(function (err) {
152149
return err;
153150
});
154-
155151
}
156152
}).catch(function (err) {
157153
return err;
158154
});
159-
// this.app.service("subscription-invitation").create(data).then(function (response){
160-
// }).catch(function(err){
161-
// return err
162-
// })
163155
}
164-
156+
165157
sendEmail(data, res, authToken) {
166158
let SendEmailBody = SendEmailBodyInvite.replace(/WriteSenderNameHere/i, data.fromEmail);
167159
SendEmailBody = SendEmailBody.replace(/DOMAIN/g, 'https://www.dashboard.' + domainKey);

service/src/services/subscription-invitation/subscription-invitation.hooks.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
let axios = require('axios');
22
let errors = require('@feathersjs/errors');
33
const async = require('asyncawait/async');
4-
const await = require('asyncawait/await');
4+
// const await = require('asyncawait/await');
55

66
module.exports = {
77
before: {
@@ -50,13 +50,10 @@ function before_create(hook) {
5050
}
5151

5252
let before_find = async((hook) => {
53-
let res = await (validateUser(hook));
54-
if (res.code == 401) {
55-
throw new errors.NotAuthenticated('Invalid token');
56-
} else {
53+
return validateUser(hook).then(result => {
5754
if(hook.params.query.own == 'false') {
5855
delete hook.params.query.own;
59-
hook.params.query.toEmail = res.data.data.email;
56+
hook.params.query.toEmail = result.data.data.email;
6057
}
6158
if (!hook.params.query.isDeleted) {
6259
hook.params.query.isDeleted = false;
@@ -68,22 +65,22 @@ let before_find = async((hook) => {
6865
hook.params.query.isDeleted = false;
6966
}
7067
}
71-
}
68+
return hook;
69+
}).catch(error=> { // eslint-disable-line no-unused-vars
70+
throw new errors.NotAuthenticated('Invalid token');
71+
});
7272
});
7373

7474
let validateUser = (data) => { // eslint-disable-line no-unused-vars
75-
return new Promise((resolve, reject) => { // eslint-disable-line no-unused-vars
76-
axios.get('http://api.' + process.env.domainKey +'/auth/api/userdetails', {
77-
strictSSL: false,
78-
headers: {
79-
'Authorization': apiHeaders.authorization // eslint-disable-line no-undef
80-
}
81-
}).then(function (response) {
82-
// console.log(response)
83-
resolve(response);
84-
}).catch(function (error) { // eslint-disable-line no-unused-vars
85-
resolve({ 'code': 401 });
86-
});
75+
return axios.get('http://api.' + process.env.domainKey +'/auth/api/userdetails', {
76+
strictSSL: false,
77+
headers: {
78+
'Authorization': apiHeaders.authorization // eslint-disable-line no-undef
79+
}
80+
}).then(function (response) {
81+
return response;
82+
}).catch(function (error) { // eslint-disable-line no-unused-vars
83+
throw(error);
8784
});
8885
};
8986

0 commit comments

Comments
 (0)