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.
This commit is contained in:
@@ -40,6 +40,32 @@ export const newProduct = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const productDetails = async (uuid) => {
|
||||
const [result] = await pool.query(
|
||||
`SELECT
|
||||
BIN_TO_UUID(p.uuid) AS uuid,
|
||||
p.name,
|
||||
p.description,
|
||||
p.price,
|
||||
p.amount,
|
||||
BIN_TO_UUID(s.uuid) AS storage_location_uuid,
|
||||
s.name AS storage_location_name,
|
||||
p.expiry_date,
|
||||
p.bottling_date,
|
||||
p.picture
|
||||
FROM products p
|
||||
JOIN storage_locations s ON p.storage_location = s.uuid
|
||||
WHERE p.uuid = UUID_TO_BIN(?)`,
|
||||
[uuid],
|
||||
);
|
||||
|
||||
if (result.length > 0) {
|
||||
return { code: "sp003", data: result[0] };
|
||||
} else {
|
||||
return { code: "ep003" };
|
||||
}
|
||||
};
|
||||
|
||||
export const allProducts = async () => {
|
||||
const [result] = await pool.query(`
|
||||
SELECT
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import express from "express";
|
||||
import dotenv from "dotenv";
|
||||
import { authenticate } from "../../services/tokenService.js";
|
||||
import { allProducts, newProduct } from "./database/products.database.js";
|
||||
import {
|
||||
allProducts,
|
||||
newProduct,
|
||||
productDetails,
|
||||
} from "./database/products.database.js";
|
||||
dotenv.config();
|
||||
const router = express.Router();
|
||||
|
||||
@@ -67,4 +71,28 @@ router.get("/all-products", authenticate, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user