getCategory update

This commit is contained in:
Mann Patel
2025-04-18 22:09:04 -06:00
parent fd43001374
commit dee6e3ce10
5 changed files with 40 additions and 2 deletions

View File

@@ -0,0 +1,25 @@
const db = require("../utils/database");
exports.getAllCategory = async (req, res) => {
try {
const [data, fields] = await db.execute(`SELECT * FROM Category`);
// Format as { ID: "", ID: "" }
const formattedData = {};
data.forEach((row) => {
formattedData[row.CategoryID] = row.Name;
});
res.json({
success: true,
message: "Categories fetched successfully",
data: formattedData,
});
} catch (error) {
console.error("Error fetching categories:", error);
return res.status(500).json({
success: false,
error: "Database error occurred",
});
}
};