{"size": 1309, "ext": "js", "max_stars_repo_path": "src/controller/users-controller.js", "max_stars_repo_name": "OluwmayowaF/twitter-clone-api", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/controller/users-controller.js", "max_issues_repo_name": "OluwmayowaF/twitter-clone-api", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/controller/users-controller.js", "max_forks_repo_name": "OluwmayowaF/twitter-clone-api", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.8, "max_line_length": 72, "alphanum_fraction": 0.5752482811}

import ErrorHandler from '../utils/error';

const User = require('../model/User');

export default {
  /**
   * Get Logged in user details
   *  @param {object} req
   * @param {object} res
   * @returns {object} res object
   */
  getLoggedInUser: async (req, res) => {
    const { id } = req.user;
    const user = await User.findById(id);
    return res.status(200).json({
      status: 'Success',
      message: 'Logged in user details',
      user,
    });
  },
  /**
   * Get a specifc user by id
   *  @param {object} req
   * @param {object} res
   * @returns {object} res object
   */
  getAUser: async (req, res) => {
    const { id } = req.params;
    const user = await User.findById(id);
    if (!user) throw new ErrorHandler(404, 'User not found');
    return res.status(200).json({
      status: 'Success',
      message: 'Found User ',
      user,
    });
  },
  /**
   * Get all registered users
   *  @param {object} req
   * @param {object} res
   * @returns {object} res object
   */
  getAllUsers: async (req, res) => {
    const users = await User.find();
    console.log(users)
    if (!users) throw new ErrorHandler(404, 'No users have registered');
    return res.status(200).json({
      status: 'Success',
      message: `${users.length} users Found`,
      users,
    });
  },
};
