Skip to content

Commit 3c54095

Browse files
authored
Merge branch 'develop' into refactor/199-cleanDocumentation
2 parents 930f2c8 + 4b0a41a commit 3c54095

4 files changed

Lines changed: 33 additions & 10 deletions

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),

middlewares/validators/validator.helper.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
328328

329329
//helper object to iterate through the items in the application and track which items are not valid.
330330
const hasValid = {
331-
resume: false,
332331
github: false,
333332
dropler: false,
334333
personal: false,
@@ -345,7 +344,6 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
345344
checkFalsy: true
346345
}).custom(app => {
347346
const jobInterests = Constants.JOB_INTERESTS;
348-
hasValid.resume = (!app.portfolioURL.resume || typeof (app.portfolioURL.resume) === "string");
349347
hasValid.github = (!app.portfolioURL.github || typeof (app.portfolioURL.github) === "string");
350348
hasValid.dropler = (!app.portfolioURL.dropler || typeof (app.portfolioURL.dropler) === "string");
351349
hasValid.personal = (!app.portfolioURL.personal || typeof (app.portfolioURL.personal) === "string");
@@ -365,7 +363,6 @@ function applicationValidator(fieldLocation, fieldname, optional = true) {
365363
} else {
366364
return application.custom(app => {
367365
const jobInterests = Constants.JOB_INTERESTS;
368-
hasValid.resume = (typeof (app.portfolioURL.resume) === "string");
369366
hasValid.github = (!app.portfolioURL.github || typeof (app.portfolioURL.github) === "string");
370367
hasValid.dropler = (!app.portfolioURL.dropler || typeof (app.portfolioURL.dropler) === "string");
371368
hasValid.personal = (!app.portfolioURL.personal || typeof (app.portfolioURL.personal) === "string");
@@ -441,7 +438,7 @@ function jwtValidator(fieldLocation, fieldname, jwtSecret, optional = true) {
441438
* @param {"query" | "body" | "header" | "param"} fieldLocation the location where the field should be found
442439
* @param {string} fieldname name of the field that needs to be validated.
443440
*/
444-
function searchModelValidator(fieldLocation, fieldName){
441+
function searchModelValidator(fieldLocation, fieldName) {
445442
const paramChain = setProperValidationChainBuilder(fieldLocation, fieldName, "Must be a valid searchable model");
446443
return paramChain.exists().withMessage("Model must be provided")
447444
.isLowercase().withMessage("Model must be lower case")
@@ -456,9 +453,11 @@ function searchModelValidator(fieldLocation, fieldName){
456453
*/
457454
function searchValidator(fieldLocation, fieldname) {
458455
const search = setProperValidationChainBuilder(fieldLocation, fieldname, "Invalid search query");
459-
456+
460457
return search.exists().withMessage("Search query must be provided")
461-
.custom((value, {req}) => {
458+
.custom((value, {
459+
req
460+
}) => {
462461
//value is a serialized JSON
463462
value = JSON.parse(value);
464463
let modelString = req.params.model
@@ -506,7 +505,9 @@ function searchSortValidator(fieldLocation, fieldName) {
506505
return searchSort.optional({
507506
checkFalsy: true
508507
})
509-
.custom((value, {req}) => {
508+
.custom((value, {
509+
req
510+
}) => {
510511
let modelString = req.params.model
511512
if (modelString.equals("hacker")) {
512513
model = Models.Hacker;

models/hacker.model.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const HackerSchema = new mongoose.Schema({
3434
//gcloud bucket link
3535
resume: {
3636
type: String,
37+
default: ""
3738
},
3839
github: {
3940
type: String
@@ -118,10 +119,9 @@ HackerSchema.methods.isApplicationComplete = function () {
118119
*/
119120
HackerSchema.statics.searchableField = function (field) {
120121
const schemaField = HackerSchema.path(field)
121-
if(schemaField != undefined){
122+
if (schemaField != undefined) {
122123
return schemaField.instance
123-
}
124-
else{
124+
} else {
125125
return null;
126126
}
127127
};

routes/api/hacker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ module.exports = {
163163
Middleware.Hacker.addDefaultStatus,
164164
Middleware.Auth.createRoleBindings(CONSTANTS.HACKER),
165165
Middleware.Hacker.createHacker,
166+
Middleware.Hacker.sendAppliedStatusEmail,
166167
Controllers.Hacker.createdHacker
167168
);
168169
/**

0 commit comments

Comments
 (0)