@@ -95,31 +95,29 @@ class Service {
9595 // previous_packages[subscriptionId].role = _.omit(previous_packages[subscriptionId].role, Role1);
9696 }
9797 /* eslint-disable no-undef */
98- /* eslint-disable */
99- console . log ( 'authorization apiHeaders>>>> ' , apiHeaders )
100- axios . put ( baseUrl + '/user/updateuserdetails/' + userId , { package : previous_packages } , { headers : { 'Authorization' : apiHeaders . authorization } } )
101- . then ( async ( ( result ) => {
102- if ( result . data . code == 201 ) {
103- let subscription_invite = await ( self . subscription_invitation ( data , res ) ) ;
104- self . sendEmail ( data , res ) ;
105- }
106- resolve ( result . data ) ;
107- } ) ) . catch ( ( err ) => {
108- console . log ( 'authorization ERROR >>>> ' , err )
109- let errorObj = { } ;
110- if ( apiHeaders . authorization == undefined ) {
111- errorObj . statusText = 'missing Authorization header' ;
112- errorObj . status = 404 ;
113- errorObj . data = '\'Auth token is required in header\'' ;
114- resolve ( errorObj ) ;
115- } else {
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+ 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 ) ) ;
110+ self . sendEmail ( data , res , params . headers . authorization ) ;
111+ }
112+ resolve ( result . data ) ;
113+ } ) ) . catch ( ( err ) => {
114+ let errorObj = { } ;
116115 errorObj . statusText = err . response . statusText ;
117116 errorObj . status = err . response . status ;
118117 errorObj . data = err . response . data ;
119118 resolve ( errorObj ) ;
120- }
121119 /* eslint-disable no-undef */
122- } ) ;
120+ } ) ;
123121 } ) ) . catch ( ( err ) => {
124122 let errorObj = { } ;
125123 errorObj . statusText = 'Not Found' ;
@@ -132,7 +130,7 @@ class Service {
132130
133131 }
134132
135- subscription_invitation ( data , res ) {
133+ subscription_invitation ( data , res ) {
136134 let self = this ;
137135 this . app . service ( 'subscription-invitation' ) . find ( { query : { 'toEmail' : data . toEmail , 'subscriptionId' : data . subscriptionId , 'isDeleted' : false } } )
138136 . then ( function ( response ) {
@@ -158,39 +156,37 @@ class Service {
158156 } ) . catch ( function ( err ) {
159157 return err ;
160158 } ) ;
161-
162-
163159 // this.app.service("subscription-invitation").create(data).then(function (response){
164160 // }).catch(function(err){
165161 // return err
166162 // })
167163 }
168164
169- sendEmail ( data , res ) {
165+ sendEmail ( data , res , authToken ) {
170166 let SendEmailBody = SendEmailBodyInvite . replace ( / W r i t e S e n d e r N a m e H e r e / i, data . fromEmail ) ;
171167 SendEmailBody = SendEmailBody . replace ( / D O M A I N / g, 'https://www.dashboard.' + domainKey ) ;
172168 SendEmailBody = SendEmailBody . replace ( / S Y S T E M N A M E / g, Object . keys ( data . role ) [ 0 ] ) ;
173169 SendEmailBody = SendEmailBody . replace ( / R O L E / g, Object . values ( data . role ) [ 0 ] ) ;
174170
175171 axios ( { method : 'post' ,
176172 url : baseUrl + '/vmailmicro/sendEmail' ,
177- headers : { 'Authorization' : apiHeaders . authorization } ,
173+ headers : { 'Authorization' : authToken } ,
178174 data : { 'to' : data . toEmail , 'from' : data . fromEmail , 'subject' : 'Invitation from Flowz' , 'body' : SendEmailBody } } ) . then ( async ( ( result ) => {
179175 return true ;
180176 } ) ) . catch ( function ( err ) {
181177 return err ;
182178 } ) ;
183179 }
184180
185- sendDeclineEmail ( params , res ) {
181+ sendDeclineEmail ( params , res , authToken ) {
186182 var SendEmailBody = SendEmailBodyDecline . replace ( / W r i t e S e n d e r N a m e H e r e / i, params . query . fromEmail ) ;
187183 SendEmailBody = SendEmailBody . replace ( / D O M A I N / g, 'https://www.dashboard.' + domainKey ) ;
188184 SendEmailBody = SendEmailBody . replace ( / S Y S T E M N A M E / g, Object . keys ( params . query . role ) [ 0 ] ) ;
189185 SendEmailBody = SendEmailBody . replace ( / R O L E / g, Object . values ( params . query . role ) [ 0 ] ) ;
190186 axios ( {
191187 method : 'post' ,
192188 url : baseUrl + '/vmailmicro/sendEmail' ,
193- headers : { 'Authorization' : apiHeaders . authorization } ,
189+ headers : { 'Authorization' : authToken } ,
194190 data : { 'to' : params . query . toEmail , 'from' : params . query . fromEmail , 'subject' : 'Your role is now no longer with Flowz.' , 'body' : SendEmailBody }
195191 } ) . then ( async ( ( result ) => {
196192 return true ;
@@ -235,23 +231,26 @@ class Service {
235231 delete previous_packages [ subscriptionId ] ;
236232 }
237233 }
238- axios . put ( baseUrl + '/user/updateuserdetails/' + userId , { package : previous_packages } , { headers : { 'Authorization' : apiHeaders . authorization } } ) . then ( async ( ( result ) => {
234+
235+ if ( ! params . headers || ! params . headers . authorization ) {
236+ let errorObj = {
237+ statusText : 'missing Authorization header' ,
238+ status : 404 ,
239+ data : '\'Auth token is required in header\''
240+ } ;
241+ resolve ( errorObj ) ;
242+ }
243+
244+ axios . put ( baseUrl + '/user/updateuserdetails/' + userId , { package : previous_packages } , { headers : { 'Authorization' : params . headers . authorization } } ) . then ( async ( ( result ) => {
239245 let subscription_invite = await ( self . subscription_invitation_remove ( params , res ) ) ;
240- self . sendDeclineEmail ( params , res ) ;
246+ self . sendDeclineEmail ( params , res , params . headers . authorization ) ;
241247 resolve ( result . data ) ;
242248 } ) ) . catch ( function ( err ) {
243249 let errorObj = { } ;
244- if ( apiHeaders . authorization == undefined ) {
245- errorObj . statusText = 'missing Authorization header' ;
246- errorObj . status = 404 ;
247- errorObj . data = '\'Auth token is required in header\'' ;
248- resolve ( errorObj ) ;
249- } else {
250- errorObj . statusText = err . response . statusText ;
251- errorObj . status = err . response . status ;
252- errorObj . data = err . response . data ;
253- resolve ( errorObj ) ;
254- }
250+ errorObj . statusText = err . response . statusText ;
251+ errorObj . status = err . response . status ;
252+ errorObj . data = err . response . data ;
253+ resolve ( errorObj ) ;
255254 } ) ;
256255 } ) ) . catch ( function ( err ) {
257256 let errorObj = { } ;
0 commit comments