Eric Whale

Add getAllusers api

......@@ -69,7 +69,20 @@ const loginUser = asyncHandler(async (req, res) => {
}
});
// @desc Get user(only self)
// @desc Get all users
// @route GET /api/users/all
// @access Public
const getAllusers = asyncHandler(async (req, res) => {
const users = await User.find()
.select("-password")
.select("-updatedAt")
.select("-createdAt")
.select("-email");
res.status(200).json(users);
});
// @desc Get user
// @route GET /api/users/self
// @access Private
const getSelf = asyncHandler(async (req, res) => {
......@@ -79,5 +92,6 @@ const getSelf = asyncHandler(async (req, res) => {
module.exports = {
signupUser,
loginUser,
getAllusers,
getSelf,
};
......
......@@ -7,7 +7,7 @@ function Userroom() {
return (
<div>
<Topbar />
<h1>Userroom page</h1>
<h1>User Room</h1>
<div>
<UserBox />
<UserBox />
......
const express = require("express");
const router = express.Router();
const { signupUser, loginUser, getSelf } = require("../actions/userActions");
const {
signupUser,
loginUser,
getAllusers,
getSelf,
} = require("../actions/userActions");
const { authHandler } = require("../middleware/authMiddleware");
router.post("/", signupUser);
router.post("/login", loginUser);
router.get("/all", getAllusers);
router.get("/self", authHandler, getSelf);
module.exports = router;
......