Skip to content
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

Added /isUsernameAvailable/:username route in users main route #140

Merged
merged 13 commits into from Mar 5, 2021

Conversation

saishankarmanugula
Copy link

Added route to check user availability. Added swagger definition and integration test for it.

image

image

if (!result.userExists) {
return res.json({
message: 'User name Available',
userExists: result.userExists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to return the data of the user with that username too? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are not returning data of user.it will return boolean false. Shall I remove 'userExists' Property and return only message in case of success?

@@ -248,6 +248,14 @@ const swaggerOptions = {
}
}
},
userAvailable: {
type: 'object',
properties: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts with the actual response sent by the route.
Is there any contract written for this API?
What is the expected response?

userExists: result.userExists
})
}
return res.boom.notFound('User name not Available')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this? As per discussed in the meeting, we were to send a 200 with userExists as false.

userExists: result.userExists
})
}
return res.boom.notFound('User name not Available')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any update on this? As per discussed in the meeting, we were to send a 200 with userExists as false.

Copy link
Contributor

@swarajpure swarajpure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting some changes. Please check

routes/users.js Outdated
* schema:
* $ref: '#/components/schemas/errors/badImplementation'
*/
router.get('/isUsernameAvailable/:username', authenticate, usersController.checkUser)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be before /:username, right? 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

try {
const result = await userQuery.fetchUser({ username: req.params.username })
return res.json({
userAvailable: !result.userExists
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be isUsernameAvailable as per API contracts

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const result = await userQuery.fetchUser({ username: req.params.username })
return res.json({
userAvailable: !result.userExists
})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The case when the user is not logged in seems to be missing 🤔

@@ -48,6 +48,25 @@ const getUser = async (req, res) => {
}
}

/**
* Checks whether a user exists or not
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be something like checks whether a given username is available

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @param res {Object} - Express response object
*/

const checkUser = async (req, res) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The function name should also be changed accordingly

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

userAvailable: {
type: 'object',
properties: {
userAvailable: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re: isUsernameAvailable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. Changed the property name only to isUsernameAvailable.

@saishankarmanugula
Copy link
Author

saishankarmanugula commented Mar 4, 2021

Please find below screenshots

image
image

The below one is without cookie.

image

@saishankarmanugula saishankarmanugula changed the title Added /userAvailable/:username route in users main route Added /isUsernameAvailable/:username route in users main route Mar 4, 2021
})
})

it('Should return userAvailable as false as we are passing existing user', function (done) {
Copy link
Contributor

@swarajpure swarajpure Mar 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: username available

swarajpure
swarajpure previously approved these changes Mar 4, 2021
Copy link
Contributor

@swarajpure swarajpure left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! 👌

Thank you for your patience with me 😂

Approving from my side

@saishankarmanugula
Copy link
Author

Looks good to me! 👌

Thank you for your patience with me 😂

Approving from my side

Thanks for all the help swaraj

* schema:
* $ref: '#/components/schemas/errors/badImplementation'
*/
router.get('/isUsernameAvailable/:username', authenticate, usersController.getUsernameAvailabilty)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API schema yet to be added to the schema file for the new route.
https://github.com/Real-Dev-Squad/website-backend/blob/develop/README.md#api-documentation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the schema file using npm run generate-api-schema. Please let me know if any further changes needs to be done

Copy link
Contributor

@ankurnarkhede ankurnarkhede left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM ✅

@ankurnarkhede ankurnarkhede merged commit bc46ea4 into Real-Dev-Squad:develop Mar 5, 2021
@swarajpure swarajpure linked an issue Mar 7, 2021 that may be closed by this pull request
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.

Create an API to check if the username is already existing
4 participants