Skip to content

Commit da5366f

Browse files
committed
Notification to Sahara Backed on Article Approve
1 parent f72cd3d commit da5366f

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

api/article/controller.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const { google } = require("googleapis");
1010
const OAuth2 = google.auth.OAuth2;
1111
const { compileTemplate } = require('../../services/handlebars');
1212
const { generateMailBody } = require('../../services/mailer');
13+
const fetch = require('node-fetch');
1314

1415
const oauth2Client = new OAuth2(
1516
process.env.CLIENT_ID,
@@ -169,6 +170,25 @@ exports.authenticateArticle = asyncHandler(async (req, res, next) => {
169170
});
170171
}
171172
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+
172192
// send Mail to the author
173193
try{
174194
await transporter.sendMail({
@@ -187,14 +207,17 @@ exports.authenticateArticle = asyncHandler(async (req, res, next) => {
187207
</html>
188208
`
189209
});
210+
190211
res.status(200).json({
191212
success: true,
192-
message: 'Article approved successfully, and notification mail sent!'
213+
message: `Article approved successfully, and notification mail sent!`,
214+
notification: notiMessage,
193215
});
194216
} catch(err) {
195217
res.status(200).json({
196218
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,
198221
});
199222
}
200223
});

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"AITOSS",
1414
"Anubhav"
1515
],
16-
"author": "Satya, Akshay",
16+
"author": "Satya, Akshay, Snehasis",
1717
"license": "ISC",
1818
"dependencies": {
1919
"axios": "^0.21.2",
@@ -33,6 +33,7 @@
3333
"html-to-text": "^6.0.0",
3434
"jsonwebtoken": "^8.5.1",
3535
"mongoose": "^5.11.9",
36+
"node-fetch": "^2.6.7",
3637
"nodemailer": "^6.4.17",
3738
"path": "^0.12.7",
3839
"xss": "^1.0.8",

0 commit comments

Comments
 (0)