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
|
Rev | Line | |
---|
[717ceae] | 1 | import express from "express";
|
---|
| 2 | import Product from "../models/productModel.js";
|
---|
| 3 |
|
---|
| 4 | const productRouter = express.Router();
|
---|
| 5 |
|
---|
| 6 | productRouter.get("/", async (req, res) => {
|
---|
| 7 | const products = await Product.find();
|
---|
| 8 | res.send(products);
|
---|
| 9 | });
|
---|
| 10 |
|
---|
| 11 | productRouter.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 |
|
---|
| 20 | productRouter.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 |
|
---|
| 29 | export default productRouter;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.