Skip to content

Conversation

@ManethKulatunge
Copy link
Contributor

@ManethKulatunge ManethKulatunge commented Dec 15, 2019

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.

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

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

  • Postman request to hacker/acceptEmail/ with email as param
  • Hacker.Test tests

Test Configuration:

Firmware version:
Hardware:
Toolchain:
SDK:

Questions for code reviewers?

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • Listed change(s) in the Changelog
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have made corresponding changes to the documentation
  • Any dependent changes have been merged and published in downstream modules

/**
* 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
Copy link
Member

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

* @param {*} next
*/
async function updateHackerByEmail(req, res, next) {
const hacker = await Services.Hacker.updateOne(req.body.hacker._id, req.body);
Copy link
Member

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”?

Copy link
Member

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;

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?

Copy link
Member

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

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


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}`)

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.


const TeamHacker0 = {
_id: Constants.MongoId.hackerAId,
email: "hello@gmail.com",

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.

@ManethKulatunge ManethKulatunge force-pushed the feature/153-accept-hacker-email branch 2 times, most recently from f54f3a2 to b17bada Compare December 16, 2019 00:39
Middleware.Auth.ensureAuthorized([Services.Hacker.findByEmail]),
Middleware.Validator.RouteParam.emailValidator,
Middleware.parseBody.middleware,
Middleware.Hacker.findByEmail,
Copy link
Member

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?

Copy link
Contributor Author

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

Copy link
Contributor Author

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;
Copy link
Member

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.

@ManethKulatunge ManethKulatunge force-pushed the feature/153-accept-hacker-email branch from 1c711ad to f067f6e Compare December 23, 2019 02:52
@ManethKulatunge ManethKulatunge force-pushed the feature/153-accept-hacker-email branch from f067f6e to 98afcf7 Compare December 30, 2019 08:13
@ManethKulatunge ManethKulatunge force-pushed the feature/153-accept-hacker-email branch from 8ef860c to 61fd988 Compare January 12, 2020 16:11
* @param {*} next
*/
async function updateHackerByEmail(req, res, next) {
const hacker = await Services.Hacker.updateOne(req.body.hacker._id, req.body);
Copy link
Member

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

@Ty-Won Ty-Won merged commit 90279b9 into develop Jan 12, 2020
@Ty-Won Ty-Won deleted the feature/153-accept-hacker-email branch January 12, 2020 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants