users

This module implements handlers for the "users" route.
Source:

Methods

(async, inner) addUser(req, res)

Source:
Handles a POST request to add a new user to the database on the endpoint /users.
Parameters:
Name Type Description
req request object - user object in body (see User model)
res response object
Returns:
  • 201: user was added
  • 400: error adding the user

(async, inner) getUser(req, res)

Source:
Handles a GET request, which will get a particular user using the given mongo id on the endpoint /users/:id
Parameters:
Name Type Description
req request object - user id given in url
res response object - user object in body (see User model)
Returns:
  • 200: the specified user was found
  • 400: given user id is not in a valid hexadecimal format
  • 404: no user was found

(async, inner) getUsers(req, res)

Source:
Handles a GET request to get all users on the database on the endpoint /users.
Parameters:
Name Type Description
req request object
res response object - a list of users (see User model)
Returns:
  • 200: JSON objects of all users
  • 500: there was an internal error trying to get all the users

(async, inner) loginUser(req, res)

Source:
Handles a POST request to verify the login credentials of a user on the endpoint /users/login.
Parameters:
Name Type Description
req request object - user object in body (see User model)
res response object
Returns:
  • 200: successfully logged in
  • 400: Error trying to login
  • 403: incorrect password

(async, inner) updateUser(req, res)

Source:
Handles a PATCH request to update a user's details on the endpoint /users/:id.
Parameters:
Name Type Description
req request object - user id in url, user object in body (see User model)
res response object - created user object
Returns:
  • 200: returns updated user details
  • 404: user not found
  • 400: error updating user