You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB
JavaScript

import express from "express";
import formidable from "express-formidable";
const router = express.Router();
import {
addProduct,
updateProductDetails,
removeProduct,
getAllProducts,
getProductById,
fetchAllProducts,
addProductReview,
fetchTopProducts,
fetchNewProducts,
filterProducts,
} from "../controllers/productController.js";
import { authenticate, authorizeAdmin } from "../middleware/authMiddleWare.js";
import checkId from "../middleware/checkId.js";
router.route("/fetchAllProducts").get(fetchAllProducts);
router.route("/:id/reviews").post(authenticate, checkId, addProductReview);
router.route("/top").get(fetchTopProducts);
router.route("/new").get(fetchNewProducts);
router
.route("/")
.post(authenticate, authorizeAdmin, formidable(), addProduct)
.get(getAllProducts);
router
.route("/:id")
.get(getProductById)
.put(authenticate, authorizeAdmin, formidable(), updateProductDetails)
.delete(authenticate, authorizeAdmin, removeProduct);
router.route("/filtered-products").post(filterProducts);
export default router;