source: backend/routes/productRoutes.js@ 717ceae

Last change on this file since 717ceae was 717ceae, checked in by Nace Gjorgjievski <nace.gorgievski123@…>, 2 years ago

connected db

  • Property mode set to 100644
File size: 789 bytes
Line 
1import express from "express";
2import Product from "../models/productModel.js";
3
4const productRouter = express.Router();
5
6productRouter.get("/", async (req, res) => {
7 const products = await Product.find();
8 res.send(products);
9});
10
11productRouter.get("/slug/:slug", async (req, res) => {
12 const product = await Product.findOne({ slug: req.params.slug });
13 if (product) {
14 res.send(product);
15 } else {
16 res.status(404).send({ message: "Продуктот не е пронајден" });
17 }
18});
19
20productRouter.get("/:id", async (req, res) => {
21 const product = await Product.findById(req.params.id);
22 if (product) {
23 res.send(product);
24 } else {
25 res.status(404).send({ message: "Продуктот не е пронајден" });
26 }
27});
28
29export default productRouter;
Note: See TracBrowser for help on using the repository browser.