-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed: Every New Broadcast should be Broadcasted to Subscribers #1128
Changes from all commits
98e0e51
74914d2
320d8ed
7a6abd0
65f9789
c2ca49d
06c0210
8f3c7f7
2973a13
1ad17fc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,16 @@ | ||
const to = require('await-to-js').default; | ||
const Broadcast = require('../../models/Broadcast'); | ||
const Subscribers = require('../../models/Subscriber'); | ||
const { ErrorHandler } = require('../../../helpers/error'); | ||
const constants = require('../../../constants'); | ||
const nodemailer = require('nodemailer') | ||
const config = require('../../../config') | ||
const { broadcastPublishMailTemplate } = require('../../../utility/emailTemplates') | ||
|
||
module.exports = async (req, res, next) => { | ||
if(Object.keys(req.body).length <= 1) { | ||
module.exports = async (req, res, next) => { | ||
if (Object.keys(req.body).length <= 1) { | ||
return res.status(200).send({ | ||
message : "Not Sufficient Data" | ||
message: "Not Sufficient Data" | ||
}) | ||
} | ||
|
||
|
@@ -15,11 +19,13 @@ | |
}; | ||
|
||
delete data.id; | ||
let approving = data?.approving | ||
delete data?.approving | ||
|
||
const [err, result] = await to(Broadcast.findOneAndUpdate({ _id : req.body.id }, { $set : data })); | ||
const [err, result] = await to(Broadcast.findOneAndUpdate({ _id: req.body.id }, { $set: data })); | ||
Check failure Code scanning / CodeQL Database query built from user-controlled sources High
This query object depends on a
user-provided value Error loading related location Loading |
||
|
||
// error occured due to the some problem | ||
if(err) { | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.DATABASE, { | ||
statusCode: 500, | ||
message: 'Database Error', | ||
|
@@ -28,21 +34,65 @@ | |
|
||
return next(error); | ||
} | ||
|
||
// if result is null that means broadcast with given id is not exist in collection | ||
if(result === null) { | ||
if (result === null) { | ||
const broadcastNotExistsError = new ErrorHandler(constants.ERRORS.INPUT, { | ||
statusCode: 400, | ||
message: 'Broadcast Not Exist...', | ||
}); | ||
|
||
return next(broadcastNotExistsError); | ||
} | ||
|
||
// success response | ||
res.status(200).send({ | ||
message : "Broadcast Updated..." | ||
var subscribers; | ||
if (approving && data?.isApproved == true) { | ||
const transporter = nodemailer.createTransport({ | ||
type: 'SMTP', | ||
host: config.EMAIL_HOST, | ||
secure: true, | ||
debug: true, | ||
port: 465, | ||
auth: { | ||
user: config.EMAIL_USER, | ||
pass: config.EMAIL_PASS, | ||
}, | ||
}); | ||
subscribers = await Subscribers.find(); | ||
subscribers = subscribers.map((subscriber) => { return subscriber?.email }) | ||
|
||
const mailOptions = { | ||
from: `HITK TECH Community <${config.EMAIL_USER}>`, | ||
to: "[email protected]", | ||
subject: `New Broadcast: ${data?.title} 😍`, | ||
html: broadcastPublishMailTemplate(data), | ||
Check failure Code scanning / CodeQL Client-side cross-site scripting High
HTML injection vulnerability due to
user-provided value Error loading related location Loading |
||
bcc: subscribers, | ||
attachments: data?.imageUrl.map((image, index) => { | ||
return { | ||
filename: `${data?.title}${index+1}`, | ||
path: image | ||
} | ||
}) | ||
}; | ||
await transporter.sendMail(mailOptions).catch((err) => { | ||
if (err) { | ||
const error = new ErrorHandler(constants.ERRORS.UNEXPECTED, { | ||
statusCode: 500, | ||
message: 'The server encountered an unexpected condition which prevented it from fulfilling the request.', | ||
errStack: err, | ||
user: req.body.email, | ||
}); | ||
throw error; | ||
} | ||
}); | ||
|
||
return next(); | ||
} | ||
|
||
|
||
|
||
|
||
// success response | ||
res.status(200).send({ | ||
message: "Broadcast Updated...", | ||
}); | ||
|
||
return next(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -207,7 +207,6 @@ | |
color: #dd2a7b; | ||
} | ||
|
||
|
||
.fa-envelope:hover, | ||
.fa-envelope-own:hover { | ||
color: #c71610; | ||
|
@@ -703,7 +702,7 @@ a > span { | |
} | ||
} | ||
|
||
@media screen and (max-width: 510px) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this change shouldn't have come here, make sure to pull the latest master, rest looks fine There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry for that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its okay, we are all learning 😊 |
||
@media screen and (max-width: 1124px) { | ||
.col .social { | ||
display: grid; | ||
grid-template-columns: 50% 50%; | ||
|
Check failure
Code scanning / CodeQL
Database query built from user-controlled sources High