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

Feat: allow to search user by email in the gateway routes #450

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/app/routes/gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ module.exports = (Router, Service) => {
});
});

Router.post('/gateway/user/findByEmail', basicAuth, async (req, res) => {
Copy link
Member

Choose a reason for hiding this comment

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

Two things:

  • Let's aim to respect REST:
    • Use a GET, not a POST, you are looking for a resource, not creating one
    • This route could be better /gateway/users with a query param called email
  • Let's not ignore errors, use a try-catch and in case the find fails, return a 500 + 'Internal Server Error' message and on the other hand, log the error so we are aware of what's going on.

const email = req.body.email.toLowerCase();
const user = await Service.User.FindUserByEmail(email).catch(() => null);
return res.status(200).send({ error: null, user });
});

Router.post('/gateway/register/stage', basicAuth, (req, res) => {
const { email } = req.body;
Service.User.CreateStaggingUser(email)
Expand Down
Loading