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

Commit 7dcc049

Browse files
authored
Merge pull request #83 from FlowzPlatform/develop
Develop
2 parents 2b2174d + bbf2008 commit 7dcc049

7 files changed

Lines changed: 145 additions & 96 deletions

File tree

finish.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ then
77
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_MASTER";
88
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_MASTER";
99
RANCHER_URL="$RANCHER_URL_MASTER";
10+
SERVICE_NAME="$SERVICE_NAME_MASTER";
1011
}
1112
elif [ "$TRAVIS_BRANCH" = "develop" ]
1213
then
@@ -17,6 +18,7 @@ then
1718
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_DEVELOP";
1819
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_DEVELOP";
1920
RANCHER_URL="$RANCHER_URL_DEVELOP";
21+
SERVICE_NAME="$SERVICE_NAME_DEVELOP";
2022
}
2123
elif [ "$TRAVIS_BRANCH" = "staging" ]
2224
then
@@ -27,19 +29,22 @@ then
2729
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_STAGING";
2830
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_STAGING";
2931
RANCHER_URL="$RANCHER_URL_STAGING";
32+
SERVICE_NAME="$SERVICE_NAME_STAGING";
3033
}
3134
else
3235
{
3336
echo "call $TRAVIS_BRANCH branch"
34-
ENV_ID=`curl -u ""$RANCHER_ACCESSKEY_QA":"$RANCHER_SECRETKEY_QA"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL_QA/v2-beta/projects?name=QA" | jq '.data[].id' | tr -d '"'`
37+
ENV_ID=`curl -u ""$RANCHER_ACCESSKEY_QA":"$RANCHER_SECRETKEY_QA"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL_QA/v2-beta/projects?name=Develop" | jq '.data[].id' | tr -d '"'`
3538
echo $ENV_ID
3639
RANCHER_ACCESSKEY="$RANCHER_ACCESSKEY_QA";
3740
RANCHER_SECRETKEY="$RANCHER_SECRETKEY_QA";
3841
RANCHER_URL="$RANCHER_URL_QA";
42+
SERVICE_NAME="$SERVICE_NAME_QA";
43+
3944
}
4045
fi
4146

42-
SERVICE_ID=`curl -u ""$RANCHER_ACCESSKEY":"$RANCHER_SECRETKEY"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL/v2-beta/projects/$ENV_ID/services?name=subscription-backend-service-flowz" | jq '.data[].id' | tr -d '"'`
47+
SERVICE_ID=`curl -u ""$RANCHER_ACCESSKEY":"$RANCHER_SECRETKEY"" -X GET -H 'Accept: application/json' -H 'Content-Type: application/json' "$RANCHER_URL/v2-beta/projects/$ENV_ID/services?name=$SERVICE_NAME" | jq '.data[].id' | tr -d '"'`
4348
echo $SERVICE_ID
4449

4550
echo "waiting for service to upgrade "

service/src/services/cb-customer/cb-customer.class.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,18 @@ class Service {
5555

5656
let getCustomerList = function (params) {
5757
let limit = params.query.limit || 10;
58+
let email = params.query.email;
59+
let first_name = params.query.first_name;
60+
let last_name = params.query.last_name;
5861

59-
return config.chargebee.customer.list({ limit: limit }).request((error, result) => {
62+
let req_obj = {
63+
limit : limit
64+
};
65+
req_obj['email[is]'] = email;
66+
req_obj['first_name[starts_with]'] = first_name;
67+
req_obj['last_name[starts_with]'] = last_name;
68+
69+
return config.chargebee.customer.list(req_obj).request((error, result) => {
6070
if (error) {
6171
return error;
6272
} else {

service/src/services/cb-plan/cb-plan.class.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class Service {
2222

2323
get (id, params) {
2424
let result = retrievePlan(id, params);
25-
2625
return Promise.resolve(result).then(res => {
2726
return res.plan;
2827
}).catch(err => {
@@ -32,7 +31,6 @@ class Service {
3231

3332
create (data, params) {
3433
let result = createPlan(data, params);
35-
3634
return Promise.resolve(result).then(res => {
3735
return res.plan;
3836
}).catch(err => {
@@ -73,7 +71,14 @@ class Service {
7371

7472
let getPlanList = function (params) {
7573
let limit = params.query.limit || 10;
76-
return config.chargebee.plan.list({ limit: limit }).request((error, result) => {
74+
let name = params.query.name;
75+
let status = params.query.status;
76+
let req_obj = {
77+
limit : limit
78+
};
79+
req_obj['name[starts_with]'] = name;
80+
req_obj['status[is]'] = status;
81+
return config.chargebee.plan.list(req_obj).request((error, result) => {
7782
if (error) {
7883
return error;
7984
} else {

service/src/services/cb-subscription/cb-subscription.class.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,13 @@ let subscriptionList = function (params) {
9696
let limit = params.query.limit || 10;
9797
let user_id = params.query.customer_id;
9898
let plan_id = params.query.plan_id;
99+
let status = params.query.status;
99100
let req_obj = {
100101
limit : limit
101102
};
102103
req_obj['customer_id[is]'] = user_id;
103104
req_obj['plan_id[is]'] = plan_id;
105+
req_obj['status[is]'] = status;
104106
return config.chargebee.subscription.list(req_obj).request(function (error, result) {
105107
if (error) {
106108
return error;

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

Lines changed: 80 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let SendEmailBodyInvite = emailTemp.sendInviteemail;
1111
let SendEmailBodyDecline = emailTemp.sendDeclineemail;
1212

1313
let domainKey = process.env.domainKey;
14-
let baseUrl = 'http://api.'+ domainKey;
14+
let baseUrl = 'https://api.'+ domainKey;
1515

1616
let schemaName = {
1717
'properties': {
@@ -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){
@@ -95,98 +95,109 @@ class Service {
9595
// previous_packages[subscriptionId].role = _.omit(previous_packages[subscriptionId].role, Role1);
9696
}
9797
/* eslint-disable no-undef */
98-
axios.put(baseUrl+'/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': apiHeaders.authorization } }).then(async ((result) => {
99-
if (result.data.code == 201) {
100-
let subscription_invite = await (self.subscription_invitation(data , res ));
101-
self.sendEmail(data, res);
102-
}
103-
resolve(result.data);
104-
}).catch((err) => {
105-
let errorObj = {};
106-
if(apiHeaders.authorization == undefined) {
107-
errorObj.statusText = 'missing Authorization header';
108-
errorObj.status = 404;
109-
errorObj.data = '\'Auth token is required in header\'';
110-
resolve (errorObj);
111-
} else {
112-
errorObj.statusText = err.response.statusText;
113-
errorObj.status = err.response.status;
114-
errorObj.data = err.response.data;
115-
resolve (errorObj);
116-
}
117-
/* eslint-disable no-undef */
118-
}));
98+
if(!params.headers || !params.headers.authorization){
99+
let errorObj = {
100+
statusText: 'missing Authorization header',
101+
status: 404,
102+
data: '\'Auth token is required in header\''
103+
};
104+
resolve (errorObj);
105+
}
106+
return self.updateuserdetails(userId,previous_packages,params).then(r => {
107+
return {res:res,userDetail:r};
108+
});
109+
}).then(async ((result)=>{
110+
let userDetailResult=result.userDetail;
111+
let res=result.res;
112+
if (userDetailResult.data.code == 201) {
113+
let subscription_invite = await (self.subscription_invitation(data, res, params ));
114+
self.sendEmail(data, res, params.headers.authorization);
115+
}
116+
resolve(userDetailResult.data);
119117
})).catch((err) => {
120118
let errorObj = {};
121-
errorObj.statusText = 'Not Found';
122-
errorObj.status = 404;
123-
errorObj.data = 'No data found with this email ID';
119+
if (err.response.data === 'data not found!') {
120+
errorObj.statusText = 'Not Found';
121+
errorObj.status = 404;
122+
errorObj.data = 'No data found with this email ID';
123+
} else {
124+
errorObj.statusText = err.response.statusText;
125+
errorObj.status = err.response.status;
126+
errorObj.data = err.response.data;
127+
}
124128
resolve(errorObj);
125129
});
126130
});
127-
128-
131+
}
132+
133+
updateuserdetails(userId,previous_packages,params){
134+
return axios.put(baseUrl+'/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': params.headers.authorization } })
135+
.then(((result) => {
136+
return result;
137+
})).catch((err) => {
138+
let errorObj = {};
139+
errorObj.statusText = err.response.statusText;
140+
errorObj.status = err.response.status;
141+
errorObj.data = err.response.data;
142+
throw(errorObj);
143+
/* eslint-disable no-undef */
144+
});
129145
}
130146

131-
subscription_invitation(data , res) {
147+
subscription_invitation(data, res, params) {
132148
let self = this;
133-
this.app.service('subscription-invitation').find({query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }})
149+
// return axios.get(baseUrl+'/subscription/subscription-invitation', {query : { 'toEmail': data.toEmail, 'subscriptionId': data.subscriptionId, 'isDeleted': false }, headers: { 'Authorization': params.headers.authorization }})
150+
return axios({
151+
method: 'get',
152+
url: baseUrl+'/subscription/subscription-invitation?toEmail='+data.toEmail+'&subscriptionId='+data.subscriptionId+'&isDeleted=false',
153+
headers: { 'Authorization': params.headers.authorization }
154+
})
134155
.then(function (response) {
135-
if (response.data.length == 0) {
136-
self.app.service('subscription-invitation').create(data).then(function (response){
156+
if (response.data.data.length == 0) {
157+
return self.app.service('subscription-invitation').create(data).then(function (response){
137158
}).catch(function(err){
138-
return err;
159+
throw(err);
139160
});
140161
} else {
141-
// console.log(response.data);
142-
response.data[0].isDeleted = true;
143-
self.app.service('subscription-invitation').patch(response.data[0].id, response.data[0] , '').then(function (response2) {
144-
// console.log('response2-----' ,response2);
162+
response.data.data[0].isDeleted = true;
163+
return self.app.service('subscription-invitation').patch(response.data.data[0].id, response.data.data[0] , '').then(function (response2) {
145164
self.app.service('subscription-invitation').create(data).then(function (response) {
146165
}).catch(function (err) {
147-
return err;
166+
throw(err);
148167
});
149168
}).catch(function (err) {
150-
return err;
169+
throw(err);
151170
});
152-
153171
}
154172
}).catch(function (err) {
155-
return err;
173+
throw(err);
156174
});
157-
158-
159-
// this.app.service("subscription-invitation").create(data).then(function (response){
160-
// }).catch(function(err){
161-
// return err
162-
// })
163175
}
164-
165-
sendEmail(data , res) {
176+
177+
sendEmail(data, res, authToken) {
166178
let SendEmailBody = SendEmailBodyInvite.replace(/WriteSenderNameHere/i, data.fromEmail);
167179
SendEmailBody = SendEmailBody.replace(/DOMAIN/g, 'https://www.dashboard.' + domainKey);
168180
SendEmailBody = SendEmailBody.replace(/SYSTEMNAME/g, Object.keys(data.role)[0]);
169181
SendEmailBody = SendEmailBody.replace(/ROLE/g, Object.values(data.role)[0]);
170-
171182
axios({ method: 'post',
172183
url: baseUrl+'/vmailmicro/sendEmail',
173-
headers: {'Authorization': apiHeaders.authorization},
184+
headers: {'Authorization': authToken},
174185
data: { 'to': data.toEmail, 'from': data.fromEmail, 'subject': 'Invitation from Flowz', 'body': SendEmailBody} }).then(async ((result) => {
175186
return true;
176187
})).catch(function(err){
177188
return err;
178189
});
179190
}
180191

181-
sendDeclineEmail(params, res) {
192+
sendDeclineEmail(params, res, authToken) {
182193
var SendEmailBody = SendEmailBodyDecline.replace(/WriteSenderNameHere/i, params.query.fromEmail);
183194
SendEmailBody = SendEmailBody.replace(/DOMAIN/g, 'https://www.dashboard.' + domainKey);
184195
SendEmailBody = SendEmailBody.replace(/SYSTEMNAME/g, Object.keys(params.query.role)[0]);
185196
SendEmailBody = SendEmailBody.replace(/ROLE/g, Object.values(params.query.role)[0]);
186197
axios({
187198
method: 'post',
188199
url: baseUrl + '/vmailmicro/sendEmail',
189-
headers: { 'Authorization': apiHeaders.authorization },
200+
headers: { 'Authorization': authToken },
190201
data: { 'to': params.query.toEmail, 'from': params.query.fromEmail, 'subject': 'Your role is now no longer with Flowz.', 'body': SendEmailBody }
191202
}).then(async ((result) => {
192203
return true;
@@ -231,23 +242,26 @@ class Service {
231242
delete previous_packages[subscriptionId];
232243
}
233244
}
234-
axios.put(baseUrl + '/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': apiHeaders.authorization }}).then(async ((result) => {
245+
246+
if(!params.headers || !params.headers.authorization){
247+
let errorObj = {
248+
statusText: 'missing Authorization header',
249+
status: 404,
250+
data: '\'Auth token is required in header\''
251+
};
252+
resolve (errorObj);
253+
}
254+
255+
axios.put(baseUrl + '/user/updateuserdetails/' + userId, { package: previous_packages }, { headers: { 'Authorization': params.headers.authorization }}).then(async ((result) => {
235256
let subscription_invite = await (self.subscription_invitation_remove(params, res));
236-
self.sendDeclineEmail(params , res);
257+
self.sendDeclineEmail(params, res, params.headers.authorization);
237258
resolve(result.data);
238259
})).catch(function (err) {
239260
let errorObj = {};
240-
if (apiHeaders.authorization == undefined) {
241-
errorObj.statusText = 'missing Authorization header';
242-
errorObj.status = 404;
243-
errorObj.data = '\'Auth token is required in header\'';
244-
resolve(errorObj);
245-
} else {
246-
errorObj.statusText = err.response.statusText;
247-
errorObj.status = err.response.status;
248-
errorObj.data = err.response.data;
249-
resolve(errorObj);
250-
}
261+
errorObj.statusText = err.response.statusText;
262+
errorObj.status = err.response.status;
263+
errorObj.data = err.response.data;
264+
resolve(errorObj);
251265
});
252266
})).catch(function (err) {
253267
let errorObj = {};

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

Lines changed: 18 additions & 21 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 (this.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,24 +65,24 @@ 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

74-
async (function 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-
});
74+
let validateUser = (data) => { // eslint-disable-line no-unused-vars
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
});
88-
});
85+
};
8986

9087

9188
function before_patch(hook) {

0 commit comments

Comments
 (0)