|
|
|
const express = require("express")
|
|
|
|
const router = express.Router()
|
|
|
|
const productController = require("../controllers/product")
|
|
|
|
const auth = require("../auth")
|
|
|
|
|
|
|
|
const { authenticateToken, verifyAdmin, } = auth
|
|
|
|
|
|
|
|
// S50
|
|
|
|
// Create a product route (accessible only by isAdmin)
|
|
|
|
router.post("/create", authenticateToken, verifyAdmin, productController.createProduct)
|
|
|
|
|
|
|
|
// Retrieve all products route (accessible to both admin and normal user)
|
|
|
|
router.get("/all", authenticateToken, verifyAdmin, productController.getAllProducts)
|
|
|
|
|
|
|
|
// Retrieve all active products route (accessible to both admin and normal user)
|
|
|
|
router.get("/active", productController.getActiveProducts)
|
|
|
|
|
|
|
|
// S51
|
|
|
|
// Retrieve a single product by ID
|
|
|
|
router.get('/products/:id', productController.getProductById);
|
|
|
|
|
|
|
|
// Update product route + admin verification
|
|
|
|
router.put('/products/:id', authenticateToken, verifyAdmin, productController.updateProduct);
|
|
|
|
|
|
|
|
// Archive a product
|
|
|
|
router.put('/products/:productId/archive', authenticateToken, verifyAdmin, productController.archiveProduct);
|
|
|
|
|
|
|
|
// Activate a product
|
|
|
|
router.put('/products/:productId/activate', authenticateToken, verifyAdmin, productController.activateProduct);
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = router
|