@@ -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 ( / D O M A I N / g, 'https://www.dashboard.' + domainKey ) ;
193206 SendEmailBody = SendEmailBody . replace ( / S Y S T E M N A M E / g, Object . keys ( data . role ) [ 0 ] ) ;
194207 SendEmailBody = SendEmailBody . replace ( / R O L E / 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