-
Notifications
You must be signed in to change notification settings - Fork 8
Feature/153 accept hacker by email #620
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
Conversation
middlewares/hacker.middleware.js
Outdated
| /** | ||
| * Updates a hacker that is specified by req.params.email, and then sets req.email | ||
| * to the email of the hacker, found in Account. | ||
| * @param {{params:{id: string}, body: *}} 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.
Is the attribute of params id, or _id? Make sure to verify this
middlewares/hacker.middleware.js
Outdated
| * @param {*} next | ||
| */ | ||
| async function updateHackerByEmail(req, res, next) { | ||
| const hacker = await Services.Hacker.updateOne(req.body.hacker._id, req.body); |
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.
We’re updating the hacker in this method by ID, so why is it called “update hacker by Email”?
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.
I think in this case you're not updating, you're just using the hacker to search for an account via ID so you can get the email, so I think you should change the middleware name and change the service method you call
| * @param {*} next | ||
| */ | ||
| function parseAcceptEmail(req, res, next) { | ||
| req.body.hacker.status = Constants.General.HACKER_STATUS_ACCEPTED; |
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.
Is there a reason this is req.body.hacker.status, i think the update middleware uses req.body.status right?
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.
agreed, the comment says req.body.status ^^ Double check it unless you changed it.
|
|
||
| /** | ||
| * @api {patch} /hacker/accept/:email accept a Hacker | ||
| * @apiName acceptHacker |
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.
Nit: update to be for accept by email
tests/hacker.test.js
Outdated
|
|
||
| it("should FAIL to accept a hacker on /api/hacker/acceptEmail/:email due to authentication", function(done) { | ||
| chai.request(server.app) | ||
| .patch(`/api/hacker/acceptEmail/${TeamHacker0.email}`) |
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.
Believe it should be the account's email as emails are tied to accounts and not hackers.
tests/util/hacker.test.util.js
Outdated
|
|
||
| const TeamHacker0 = { | ||
| _id: Constants.MongoId.hackerAId, | ||
| email: "hello@gmail.com", |
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.
Emails are tied to accounts not hackers.
f54f3a2 to
b17bada
Compare
| Middleware.Auth.ensureAuthorized([Services.Hacker.findByEmail]), | ||
| Middleware.Validator.RouteParam.emailValidator, | ||
| Middleware.parseBody.middleware, | ||
| Middleware.Hacker.findByEmail, |
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.
is middleware hacker findByEmail and then calling middleware findByEmail duplicate work?
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.
Yeah I believe so I'll fix it
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.
Edit: req.body.hacker is changed by findByEmail so no it is not duplicated work
| * @param {*} next | ||
| */ | ||
| function parseAcceptEmail(req, res, next) { | ||
| req.body.hacker.status = Constants.General.HACKER_STATUS_ACCEPTED; |
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.
agreed, the comment says req.body.status ^^ Double check it unless you changed it.
1c711ad to
f067f6e
Compare
f067f6e to
98afcf7
Compare
8ef860c to
61fd988
Compare
middlewares/hacker.middleware.js
Outdated
| * @param {*} next | ||
| */ | ||
| async function updateHackerByEmail(req, res, next) { | ||
| const hacker = await Services.Hacker.updateOne(req.body.hacker._id, req.body); |
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.
I think in this case you're not updating, you're just using the hacker to search for an account via ID so you can get the email, so I think you should change the middleware name and change the service method you call
Tickets:
List of changes:
-Added a route to accept hacker by email
-Made changes to middleware to allow aforementioned change
Type of change
Please delete options that are not relevant.
How has this been tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Test Configuration:
Firmware version:
Hardware:
Toolchain:
SDK:
Questions for code reviewers?
Checklist: