diff --git a/.gitignore b/.gitignore index cb65a0e..6588b4d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /coverage /uploads /.vscode +/dist diff --git a/src/routes/productsRoute.ts b/src/routes/productsRoute.ts index bd5b09f..2e3fee0 100644 --- a/src/routes/productsRoute.ts +++ b/src/routes/productsRoute.ts @@ -1,31 +1,38 @@ import { Router } from "express"; import { upload } from "../utils/uploadImages"; -import { fetchProducts, addProducts, fetchSingleProduct, productsUpdate, removeProducts, productAvailability,searchProductController} from "../controllers/productControllers"; +import { + fetchProducts, + addProducts, + fetchSingleProduct, + productsUpdate, + removeProducts, + productAvailability, + searchProductController, +} from "../controllers/productControllers"; import { validateSchema } from "../middlewares/validator"; import { productDataSchema } from "../schemas/productSchema"; import { isAseller } from "../middlewares/sellerAuth"; import { isLoggedIn } from "../middlewares/isLoggedIn"; import { isCategoryExist } from "../middlewares/isCategoryExist"; -import { addReviewController, deleteReviewController, getreviewController, updateReviewController} from "../controllers/productControllers" +import { addReviewController, deleteReviewController, getreviewController, updateReviewController } from "../controllers/productControllers"; import { addReviewValidate, updateReviewValidate } from "../schemas/review"; import { hasPurchasedProduct } from "../middlewares/hasPurchased"; import { isPasswordOutOfDate } from "../middlewares/isPasswordOutOfDate"; import { getAds } from "../controllers/adsController"; const productsRouter = Router(); -productsRouter.get("/search",isPasswordOutOfDate, searchProductController) -productsRouter.get('/ads', getAds); +productsRouter.get("/search", searchProductController); +productsRouter.get("/ads", getAds); -productsRouter.get("/",fetchProducts); -productsRouter.get("/:id",fetchSingleProduct); -productsRouter.post("/",isLoggedIn,isPasswordOutOfDate,isAseller,upload.array('images'), -validateSchema(productDataSchema),isCategoryExist,addProducts); -productsRouter.patch("/:id",isLoggedIn,isPasswordOutOfDate,isAseller,upload.array('images'),productsUpdate); -productsRouter.patch("/:id/status",isLoggedIn,isPasswordOutOfDate,isAseller,productAvailability); -productsRouter.delete("/:id",isLoggedIn,isPasswordOutOfDate,isAseller,removeProducts); +productsRouter.get("/", fetchProducts); +productsRouter.get("/:id", fetchSingleProduct); +productsRouter.post("/", isLoggedIn, isPasswordOutOfDate, isAseller, upload.array("images"), validateSchema(productDataSchema), isCategoryExist, addProducts); +productsRouter.patch("/:id", isLoggedIn, isPasswordOutOfDate, isAseller, upload.array("images"), productsUpdate); +productsRouter.patch("/:id/status", isLoggedIn, isPasswordOutOfDate, isAseller, productAvailability); +productsRouter.delete("/:id", isLoggedIn, isPasswordOutOfDate, isAseller, removeProducts); -productsRouter.get("/:pid/reviews", getreviewController) -productsRouter.post("/:pid/reviews",isLoggedIn,isPasswordOutOfDate,validateSchema(addReviewValidate), hasPurchasedProduct, addReviewController) -productsRouter.delete("/:pid/reviews", isLoggedIn,isPasswordOutOfDate, deleteReviewController) -productsRouter.patch("/:pid/reviews", isLoggedIn,isPasswordOutOfDate, validateSchema(updateReviewValidate), updateReviewController) -export default productsRouter; \ No newline at end of file +productsRouter.get("/:pid/reviews", getreviewController); +productsRouter.post("/:pid/reviews", isLoggedIn, isPasswordOutOfDate, validateSchema(addReviewValidate), hasPurchasedProduct, addReviewController); +productsRouter.delete("/:pid/reviews", isLoggedIn, isPasswordOutOfDate, deleteReviewController); +productsRouter.patch("/:pid/reviews", isLoggedIn, isPasswordOutOfDate, validateSchema(updateReviewValidate), updateReviewController); +export default productsRouter; diff --git a/src/services/product.service.ts b/src/services/product.service.ts index 7e9e817..ff18d7e 100644 --- a/src/services/product.service.ts +++ b/src/services/product.service.ts @@ -99,7 +99,7 @@ export const createProducts = async (data: ProductType) => { }; export const updateProducts = async (req: Request, res: Response) => { - const { name, stockQuantity, price, discount, categoryID, expiryDate }: any = req.body; + const { name, stockQuantity, price, discount, categoryID, expiryDate, description }: any = req.body; try { let uploadedImages: any; let url: any[] = []; @@ -131,6 +131,7 @@ export const updateProducts = async (req: Request, res: Response) => { price: price || product.price, discount: discount || product.discount, categoryID: categoryID || product.categoryID, + description: description || product.description, expiryDate: expiryDate || product.expiryDate, }); return updateProduct;