product page updated
This commit is contained in:
parent
5b70fde8cd
commit
cea8a002fe
@ -1,5 +1,5 @@
|
||||
import express from "express";
|
||||
import { isAuthenticatedUser } from "../../middlewares/auth.js";
|
||||
import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
import {
|
||||
addCategory,
|
||||
deleteCategory,
|
||||
@ -8,9 +8,17 @@ import {
|
||||
} from "./categoryController.js";
|
||||
const router = express.Router();
|
||||
|
||||
router.route("/add").post(isAuthenticatedUser, addCategory);
|
||||
router.route("/getCategories").get(isAuthenticatedUser, getCategories);
|
||||
router.route("/update/:_id").patch(isAuthenticatedUser, updateCategory);
|
||||
router.route("/delete/:_id").delete(isAuthenticatedUser, deleteCategory);
|
||||
router
|
||||
.route("/add")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), addCategory);
|
||||
router
|
||||
.route("/getCategories")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getCategories);
|
||||
router
|
||||
.route("/update/:_id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateCategory);
|
||||
router
|
||||
.route("/delete/:_id")
|
||||
.delete(isAuthenticatedUser, authorizeRoles("admin"), deleteCategory);
|
||||
|
||||
export default router;
|
||||
|
@ -34,7 +34,7 @@ export const createProduct = async (req, res) => {
|
||||
}
|
||||
|
||||
req.body.image = imagesLinks;
|
||||
req.body.addedBy = req.user.id;
|
||||
req.body.addedBy = req.user._id;
|
||||
const newUniquid = uuidv4();
|
||||
req.body.uniqueId = newUniquid.replace(/-/g, "").substring(0, 10);
|
||||
|
||||
@ -54,7 +54,9 @@ export const createProduct = async (req, res) => {
|
||||
//get All Product
|
||||
export const getAllProduct = async (req, res) => {
|
||||
try {
|
||||
const product = await Product.find().sort({ createdAt: -1 });
|
||||
const product = await Product.find({ addedBy: req.user._id }).sort({
|
||||
createdAt: -1,
|
||||
});
|
||||
if (product) {
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
|
@ -12,8 +12,12 @@ import { isAuthenticatedUser, authorizeRoles } from "../../middlewares/auth.js";
|
||||
router
|
||||
.route("/product/create/")
|
||||
.post(isAuthenticatedUser, authorizeRoles("admin"), createProduct);
|
||||
router.route("/product/getAll/").get(getAllProduct);
|
||||
router.route("/product/getOne/:id").get(getOneProduct);
|
||||
router
|
||||
.route("/product/getAll/")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getAllProduct);
|
||||
router
|
||||
.route("/product/getOne/:id")
|
||||
.get(isAuthenticatedUser, authorizeRoles("admin"), getOneProduct);
|
||||
router
|
||||
.route("/product/update/:id")
|
||||
.patch(isAuthenticatedUser, authorizeRoles("admin"), updateProduct);
|
||||
|
Loading…
Reference in New Issue
Block a user