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

Zhifan created registration api endpoints #1200

Open
wants to merge 6 commits into
base: development
Choose a base branch
from

Conversation

mashpotato9
Copy link

Description

Screenshot 2025-01-21 at 5 36 18 PM

Related PRS (if any):

This backend PR is not related to frontend PR.

Main changes explained:

  • Created registration schema, controller and router
  • Added registration endpoints to the routes

How to test:

  1. check into current branch
  2. do npm run build and npm start to run this PR locally
  3. Clear site data/cache
  4. retrieve token by logging in
  5. retrieve user id from database
  6. generate a object id from here as event id
  7. submit post request to http://localhost:4500/api/register/create and http://localhost:4500/api/register/cancel with the following format to verify
Screenshot 2025-01-21 at 6 15 02 PM Screenshot 2025-01-21 at 6 15 32 PM

Screenshots or videos of changes:

summary.mp4

Note:

Include the information the reviewers need to know.

Copy link

@sabithanazareth sabithanazareth left a comment

Choose a reason for hiding this comment

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

I have tested the API endpoints, and they work as expected. However, I recommend implementing trimming for the parameters received from the request body to prevent issues caused by unintended whitespace in the input.

PR.1200.mp4

Comment on lines +16 to +17
const { eventId } = req.body;
const userId = req.body.requestor.requestorId;

Choose a reason for hiding this comment

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

Suggested change
const { eventId } = req.body;
const userId = req.body.requestor.requestorId;
const { eventId } = req.body.eventId?.trim();
const userId = req.body.requestor?.requestorId?.trim();

Recommend trimming eventId and requestorId using .trim() to ensure no unintended leading or trailing spaces.

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the review and suggestion. However, in this case, trimming might not be necessary since both eventId/registrationId and userId are MongoDB ObjectIds that come from our system (database and authentication) rather than direct user input. The existing MongoDB ObjectId validation mongoose.Types.ObjectId.isValid() will catch any malformed IDs. If we do need to handle string cleaning in the future, I think it would be better handled at the input validation layer or form processing level prior to passing into the controller.

Copy link

@Eveye2023 Eveye2023 left a comment

Choose a reason for hiding this comment

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

The API endpoints works as exptected. The code is very clear and easy to read.
There may be a minor issue with the error message, which I've mentioned in the code details.

Screen.Recording.2025-01-29.at.11.31.40.AM.mov


if (!mongoose.Types.ObjectId.isValid(registrationId)) {
return res.status(400).send({ error: 'Invalid registration ID format' });
}

Choose a reason for hiding this comment

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

Is registrationId required here? If so, perhaps we should add a condition to check if it is empty first. Currently, if I don't provide a registrationId when making the cancel request, the error message returned is 'Invalid registration ID format.'

Copy link
Author

Choose a reason for hiding this comment

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

yes it should be required and theres a chain of methods in the router for validation. I looked into it and add a middleware to enforced the validation. Please review it again.

Choose a reason for hiding this comment

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

Now I can get the right error message. Everything's good on my side. Great job!

@fangedShadow
Copy link

The API endpoints works as exptected. The test went as it was explained and done in the video.

20250130-1706-20.3932015.mp4

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.

4 participants