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