diff --git a/backend/controllers/transaction.js b/backend/controllers/transaction.js index 60592e4..63e59a0 100644 --- a/backend/controllers/transaction.js +++ b/backend/controllers/transaction.js @@ -91,12 +91,17 @@ exports.getAllTransactions = async (req, res) => { try { const [transactions] = await db.execute( `SELECT - TransactionID, - UserID, - ProductID, - Date, - PaymentStatus - FROM Transaction` + T.TransactionID, + T.UserID, + T.ProductID, + T.Date, + T.PaymentStatus, + P.Name AS ProductName, + MIN(I.URL) AS Image_URL + FROM Transaction T + JOIN Product P ON T.ProductID = P.ProductID + LEFT JOIN Image_URL I ON P.ProductID = I.ProductID + GROUP BY T.TransactionID, T.UserID, T.ProductID, T.Date, T.PaymentStatus, P.Name` ); res.json({ diff --git a/backend/routes/transaction.js b/backend/routes/transaction.js index b9ccb75..ba84a6a 100644 --- a/backend/routes/transaction.js +++ b/backend/routes/transaction.js @@ -19,7 +19,7 @@ router.get("/getTransactionsByProduct/:productID", txCtrl.getTransactionsByProdu router.post("/getTransactionsByUser", txCtrl.getTransactionsByUser); // Get all transactions in the system -router.get("/getAllTransactions", txCtrl.getAllTransactions); +router.post("/getAllTransactions", txCtrl.getAllTransactions); // Update payment status on a transaction router.patch("/updatePaymentStatus", txCtrl.updatePaymentStatus); diff --git a/frontend/src/pages/Transactions.jsx b/frontend/src/pages/Transactions.jsx index 01ace39..147656b 100644 --- a/frontend/src/pages/Transactions.jsx +++ b/frontend/src/pages/Transactions.jsx @@ -9,7 +9,7 @@ const Transactions = () => { const fetchTransactions = async () => { try { const response = await fetch( - "http://localhost:3030/api/transaction/getTransactionsByUser", + "http://localhost:3030/api/transaction/getAllTransactions", { method: "POST", headers: { "Content-Type": "application/json" },