@@ -10,6 +10,7 @@ const { google } = require("googleapis");
10
10
const OAuth2 = google . auth . OAuth2 ;
11
11
const { compileTemplate } = require ( '../../services/handlebars' ) ;
12
12
const { generateMailBody } = require ( '../../services/mailer' ) ;
13
+ const fetch = require ( 'node-fetch' ) ;
13
14
14
15
const oauth2Client = new OAuth2 (
15
16
process . env . CLIENT_ID ,
@@ -169,6 +170,25 @@ exports.authenticateArticle = asyncHandler(async (req, res, next) => {
169
170
} ) ;
170
171
}
171
172
await Article . findByIdAndUpdate ( articleId , { isAuthentic : true } ) ;
173
+
174
+ // Notification to Sahara Backend
175
+ let notiMessage = '' ;
176
+ try {
177
+ const noti_response = await fetch ( process . env . NOTIFICATION_URL , {
178
+ method : 'POST' ,
179
+ body : articleDetails ,
180
+ headers : { 'Authorization' : `Bearer ${ process . env . NOTIFICATION_TOKEN } ` } ,
181
+ }
182
+ ) ;
183
+ // console.log(noti_response);
184
+ if ( noti_response . status === 200 ) {
185
+ notiMessage = `Notification sent successfully!` ;
186
+ } ;
187
+ } catch ( error ) {
188
+ console . log ( error ) ;
189
+ notiMessage = `Notification failed! - ${ error } ` ;
190
+ }
191
+
172
192
// send Mail to the author
173
193
try {
174
194
await transporter . sendMail ( {
@@ -187,14 +207,17 @@ exports.authenticateArticle = asyncHandler(async (req, res, next) => {
187
207
</html>
188
208
`
189
209
} ) ;
210
+
190
211
res . status ( 200 ) . json ( {
191
212
success : true ,
192
- message : 'Article approved successfully, and notification mail sent!'
213
+ message : `Article approved successfully, and notification mail sent!` ,
214
+ notification : notiMessage ,
193
215
} ) ;
194
216
} catch ( err ) {
195
217
res . status ( 200 ) . json ( {
196
218
success : true ,
197
- message : 'Article approved successfully, but there was some problem in sending approval notification mail to the autor.'
219
+ message : `Article approved successfully, but there was some problem in sending approval notification mail to the author.` ,
220
+ notification : notiMessage ,
198
221
} ) ;
199
222
}
200
223
} ) ;
0 commit comments