-
Notifications
You must be signed in to change notification settings - Fork 8
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
Feature/254 batch actions #600
base: develop
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error-handling should be done via next(<err message>);
. See this example for reference.
This way, *.controller.js
only handles successes.
@@ -62,6 +61,48 @@ async function executeQuery(req, res, next) { | |||
return next(); | |||
} | |||
|
|||
/** | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to flesh out this comment so we know what this function does :)!
} | ||
|
||
/** | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto about the comment
@@ -62,6 +61,48 @@ async function executeQuery(req, res, next) { | |||
return next(); | |||
} | |||
|
|||
/** | |||
* | |||
* @param {} req |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding what attributes this function expects to be inside of req
.
|
||
/** | ||
* | ||
* @param {} req |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding what attributes this function expects to be inside of req
.
"data": {} | ||
} | ||
* | ||
* @apiSuccess {String} message Error message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be @apiError
query.sort(sort_by); | ||
query.sort(sortBy); | ||
} | ||
return query.limit(limit).skip(limit * page) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
|
@@ -11,4 +11,24 @@ module.exports = { | |||
VALIDATOR.booleanValidator("query", "expand", true), | |||
VALIDATOR.searchValidator("query", "q") | |||
], | |||
statusValidator: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we match syntax with other routes?
}, | ||
"sendEmails": { | ||
requestType: Constants.REQUEST_TYPES.GET, | ||
uri: "/api/search/sendEmails", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: