Skip to content

Commit 4b0a41a

Browse files
authored
Merge pull request #206 from hackmcgill/bugfix/205-appliedEmail
Add new middleware that blindly sends the HACKER_STATUS_APPLIED email
2 parents cd80279 + d64ecd0 commit 4b0a41a

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

middlewares/hacker.middleware.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,26 @@ async function sendStatusUpdateEmail(req, res, next) {
243243
Services.Email.sendStatusUpdate(account.firstName, account.email, req.body.status, next);
244244
}
245245
}
246+
247+
/**
248+
* Sends an email telling the user that they have applied. This is used exclusively when we POST a hacker.
249+
* @param {{body: {hacker: {accountId: string}}}} req
250+
* @param {*} res
251+
* @param {(err?:*)=>void} next
252+
*/
253+
async function sendAppliedStatusEmail(req, res, next) {
254+
const hacker = req.body.hacker;
255+
const account = await Services.Account.findById(hacker.accountId);
256+
if (!account) {
257+
return next({
258+
status: 500,
259+
message: Constants.Error.GENERIC_500_MESSAGE,
260+
error: {}
261+
});
262+
}
263+
Services.Email.sendStatusUpdate(account.firstName, account.email, Constants.General.HACKER_STATUS_APPLIED, next);
264+
}
265+
246266
/**
247267
* If the current hacker's status is Constants.HACKER_STATUS_NONE, and the hacker's application is completed,
248268
* then it will change the status of the hacker to Constants.General.HACKER_STATUS_APPLIED, and then email the hacker to
@@ -450,6 +470,7 @@ module.exports = {
450470
uploadResume: Middleware.Util.asyncMiddleware(uploadResume),
451471
downloadResume: Middleware.Util.asyncMiddleware(downloadResume),
452472
sendStatusUpdateEmail: Middleware.Util.asyncMiddleware(sendStatusUpdateEmail),
473+
sendAppliedStatusEmail: Middleware.Util.asyncMiddleware(sendAppliedStatusEmail),
453474
updateHacker: Middleware.Util.asyncMiddleware(updateHacker),
454475
validateConfirmedStatus: Middleware.Util.asyncMiddleware(validateConfirmedStatus),
455476
checkDuplicateAccountLinks: Middleware.Util.asyncMiddleware(checkDuplicateAccountLinks),

routes/api/hacker.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = {
4848
Middleware.Auth.ensureAuthorized(),
4949

5050
Middleware.Hacker.findSelf,
51-
Controllers.Hacker.showHacker,
51+
Controllers.Hacker.showHacker
5252
);
5353

5454
/**
@@ -112,6 +112,7 @@ module.exports = {
112112
Middleware.Hacker.addDefaultStatus,
113113
Middleware.Auth.createRoleBindings(CONSTANTS.HACKER),
114114
Middleware.Hacker.createHacker,
115+
Middleware.Hacker.sendAppliedStatusEmail,
115116
Controllers.Hacker.createdHacker
116117
);
117118
/**

0 commit comments

Comments
 (0)