Implement the Get All Users Controller

Add a controller function that calls the getAllUsers service.

The response should contain a success flag and a data array.

Return HTTP 200 when the request succeeds.

Get All Users Controller
export async function getAllUsers(req, res, next) {
  try {
    const users = await userService.getAllUsers();

    res.status(200).json({
      success: true,
      count: users.length,
      data: users
    });
  } catch (error) {
    next(error);
  }
}

Retrieves the user collection through the service and returns the result in a JSON response.

Key Takeaways
  • GET endpoints retrieve resources.

  • Return an array when listing multiple resources.

  • Never expose password fields in API responses.