Commit 249022e7 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

create: products api;

parent 4f5be806
import { Request, Response } from "express";
import db from "../models/prismaClient";
const ProductController = { const ProductController = {
/**
*
* @param {Request} req
* @param {Response} res
*/
async index(req, res) {
let product = await db.product.findMany();
await db.$disconnect()
res.json(product)
},
};
} export default ProductController;
export default ProductController;
\ No newline at end of file
...@@ -4,6 +4,7 @@ import UserController from "../controllers/UserController"; ...@@ -4,6 +4,7 @@ import UserController from "../controllers/UserController";
import adminRouter from "./admin"; import adminRouter from "./admin";
import { JwtAdminMiddleware } from "./middleware"; import { JwtAdminMiddleware } from "./middleware";
import CategoryController from "../controllers/CategoryController"; import CategoryController from "../controllers/CategoryController";
import ProductController from "../controllers/ProductController";
const route = express.Router(); const route = express.Router();
route.use("/admin/", JwtAdminMiddleware, adminRouter); route.use("/admin/", JwtAdminMiddleware, adminRouter);
...@@ -12,5 +13,6 @@ route.get("/user", UserController.index); ...@@ -12,5 +13,6 @@ route.get("/user", UserController.index);
route.post("/user/auth", UserController.login); route.post("/user/auth", UserController.login);
route.post("/user", UserController.create); route.post("/user", UserController.create);
route.get('/category', CategoryController.index) route.get('/category', CategoryController.index)
route.get('/product', ProductController.index)
export default route; export default route;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment