Conversation
pierreTklein
left a comment
There was a problem hiding this comment.
Cool work! Check my comments for fixes.
| async function emailResults(req, res) { | ||
| let results = req.body.results; | ||
| let message; | ||
| if (results === undefined) { |
There was a problem hiding this comment.
Error-handling should be done via next(<err message>);. See this example for reference.
This way, *.controller.js only handles successes.
| } | ||
|
|
||
| /** | ||
| * |
There was a problem hiding this comment.
Make sure to flesh out this comment so we know what this function does :)!
| } | ||
|
|
||
| /** | ||
| * |
|
|
||
| /** | ||
| * | ||
| * @param {} req |
There was a problem hiding this comment.
Consider adding what attributes this function expects to be inside of req.
|
|
||
| /** | ||
| * | ||
| * @param {} req |
There was a problem hiding this comment.
Consider adding what attributes this function expects to be inside of req.
| "data": {} | ||
| } | ||
| * | ||
| * @apiSuccess {String} message Error message |
| query.sort(sort_by); | ||
| query.sort(sortBy); | ||
| } | ||
| return query.limit(limit).skip(limit * page) |
There was a problem hiding this comment.
What happens if limit / page are undefined?
| * @returns {Promise<[Array]>} | ||
| * @description Builds and executes a status update based on a subset of mongodb | ||
| */ | ||
| function executeStatusAction(model, queryArray, page, limit, sort, sortBy, update, shouldExpand = false) { |
There was a problem hiding this comment.
This method is more generic than executeStatus. This is a batch update for any model based on a query and a model. Therefore, the method name should reflect that.
| * @description Sends a status update email based on a subset of mongodb | ||
| */ | ||
| async function executeEmailAction(model, queryArray, page, limit, sort, sortBy, status, shouldExpand = false) { | ||
| var query = createQuery(model, queryArray, page, limit, sort, sortBy, shouldExpand); |
There was a problem hiding this comment.
This logic should not necessarily be in the executeEmailAction method, or at least if it is, then the parameters should reflect some sort of restrictions. For example, the code below assumes that the model is of type Hacker. However, the method parameters take in a model object!
I would recommend this function be used only for Hacker objects, since it send a status update email. Because of this, the function name should change to reflect this.
|
| VALIDATOR.booleanValidator("query", "expand", true), | ||
| VALIDATOR.searchValidator("query", "q") | ||
| ], | ||
| statusValidator: [ |
There was a problem hiding this comment.
Does this validator validate for status? It seems not necessarily a search and update status validator, but rather a search and update hacker validator?
There was a problem hiding this comment.
Also, note that you can chain validator middlewares in the route as well! Consider that both your new validators perform the function of 'check for valid search' + 'check for something else', and searchQueryValidator already performs the first part of that. Instead of having your validators duplicate this code, you could chain searchQueryValidator as well as statusValidator in the route.
| VALIDATOR.searchValidator("query", "q"), | ||
| VALIDATOR.updateHackerValidator("query", "update") | ||
| ], | ||
| emailValidator: [ |
There was a problem hiding this comment.
Same notes as above, but also, it's kinda weird that the emailValidator checks the status? I see this is being used in the bulk email endpoint, but should the name of a thing describe what it does, or where it's being used? What kind of coupling does that cause?
| Middleware.Validator.Search.emailValidator, | ||
| Middleware.parseBody.middleware, | ||
| Middleware.Search.parseQuery, | ||
| Middleware.Search.executeEmailAction, |
There was a problem hiding this comment.
This endpoint is interesting. The name sounds like a generic 'send emails' route. The middleware names look like generic 'send emails' validators. But 'emailValidator' validates for 'search + status', and then the executeEmailAction middleware ends up calling a service that seems to only send status update emails. I believe there's a mismatch between what this endpoint says it's doing, and what it actually does.
Are there plans to expand the functionality of the route? I think aligning functionality and naming would help. Also, if this is solely a status email sender, consider (from a comment above):
[...,
Middleware.Validator.Search.searchQueryValidator,
Middleware.Validator.Search.statusValidator,
...]
Does that align more or less with what this endpoint currently does?
YiFeiZhang2
left a comment
There was a problem hiding this comment.
Nice work! My comments really deal with maintainability rather than functionality.
I think the biggest thing for me was a bit of confusion between the names of things and what they actually do.
| */ | ||
| searchRouter.route("/updateStatus").get( | ||
| Middleware.Auth.ensureAuthenticated(), | ||
| Middleware.Auth.ensureAuthorized(), |
There was a problem hiding this comment.
Make sure only admins / staff are able to change this status!
| */ | ||
| searchRouter.route("/sendEmails").get( | ||
| Middleware.Auth.ensureAuthenticated(), | ||
| Middleware.Auth.ensureAuthorized(), |
There was a problem hiding this comment.
Make sure only admins / staff are able to send emails too
| }, | ||
| "updateStatus": { | ||
| requestType: Constants.REQUEST_TYPES.GET, | ||
| uri: "/api/search/updateStatus", |
There was a problem hiding this comment.
can we match syntax with other routes?
| }, | ||
| "sendEmails": { | ||
| requestType: Constants.REQUEST_TYPES.GET, | ||
| uri: "/api/search/sendEmails", |
There was a problem hiding this comment.
can we match syntax with other routes?
|
Any updates on this PR? |
|
@pierreTklein backlogged for now |
Description
Allows batch actions (hacker status updates and sending emails) for a search query provided.
Currently, updateStatus only works for hacker models, change name to updateHackerStatuses and sendEmailsToHackers?
Fixes #254 #276
Type of change
How Has This Been Tested?
Tested manually with queries of hackers.
Checklist: