Files
stockhome/backend/routes/app/products.route.js
T
theis.gaedigk 616058b603 feat: add profile route and sidebar navigation; implement inventory and view product pages
- Added a new profile route under the hidden layout.
- Introduced a Sidebar component for navigation between inventory, add product, and profile pages.
- Created InventoryPage to display a list of products with sorting and pagination.
- Implemented ViewProduct page to show details of a selected product.
- Integrated API calls for fetching products and product details.
- Updated route tree to include new routes and components.
2026-05-26 21:37:30 +02:00

99 lines
1.9 KiB
JavaScript

import express from "express";
import dotenv from "dotenv";
import { authenticate } from "../../services/tokenService.js";
import {
allProducts,
newProduct,
productDetails,
} from "./database/products.database.js";
dotenv.config();
const router = express.Router();
router.post("/new-product", authenticate, async (req, res) => {
const {
name,
description,
price,
amount,
storage_location,
expiry_date,
bottling_date,
} = req.body;
const result = await newProduct(
name,
description,
price,
amount,
storage_location,
expiry_date,
bottling_date,
);
if (result.code === "ep001") {
res.status(406).json({
success: false,
code: "ep001",
data: null,
message: "Error while creating product",
});
}
if (result.code === "sp001") {
res.status(201).json({
success: true,
code: "sp001",
data: null,
message: "",
});
}
});
router.get("/all-products", authenticate, async (req, res) => {
const result = await allProducts();
if (result.code === "ep002") {
res.status(406).json({
success: false,
code: "ep002",
data: null,
message: "Error while fetching products",
});
}
if (result.code === "sp002") {
res.status(200).json({
success: true,
code: "sp002",
data: result.data,
message: "",
});
}
});
router.get("/view", authenticate, async (req, res) => {
const uuid = req.query.uuid;
const result = await productDetails(uuid);
if (result.code === "ep003") {
res.status(406).json({
success: false,
code: "ep003",
data: null,
message: "Error while fetching product",
});
}
if (result.code === "sp003") {
res.status(200).json({
success: true,
code: "sp003",
data: result.data,
message: "",
});
}
});
export default router;