adding stuff to the onClick
This commit is contained in:
@@ -7,10 +7,11 @@ exports.createTransaction = async (req, res) => {
|
||||
const { userID, productID, date, paymentStatus } = req.body;
|
||||
|
||||
try {
|
||||
const formattedDate = new Date(date).toISOString().slice(0, 19).replace("T", " ");
|
||||
const [result] = await db.execute(
|
||||
`INSERT INTO Transaction (UserID, ProductID, Date, PaymentStatus)
|
||||
VALUES (?, ?, ?, ?)`,
|
||||
[userID, productID, date, paymentStatus]
|
||||
[userID, productID, formattedDate, paymentStatus]
|
||||
);
|
||||
|
||||
res.json({
|
||||
|
||||
@@ -4,6 +4,7 @@ const pool = mysql.createPool({
|
||||
host: "localhost",
|
||||
user: "root",
|
||||
database: "Marketplace",
|
||||
password: "12345678"
|
||||
});
|
||||
|
||||
module.exports = pool.promise();
|
||||
|
||||
@@ -18,7 +18,7 @@ async function sendVerificationEmail(email, verificationCode) {
|
||||
|
||||
// Clean up expired verification codes (run this periodically)
|
||||
function cleanupExpiredCodes() {
|
||||
db_con.query(
|
||||
db.query(
|
||||
"DELETE FROM AuthVerification WHERE Date < DATE_SUB(NOW(), INTERVAL 15 MINUTE) AND Authenticated = 0",
|
||||
(err, result) => {
|
||||
if (err) {
|
||||
|
||||
@@ -417,7 +417,39 @@ const ProductDetail = () => {
|
||||
|
||||
<div className="relative">
|
||||
<button
|
||||
onClick={() => setShowContactOptions(!showContactOptions)}
|
||||
onClick={async () => {
|
||||
try {
|
||||
// Create a transaction record
|
||||
const transactionData = {
|
||||
userID: storedUser.ID, // User ID from session storage
|
||||
productID: product.ProductID, // Product ID from the product details
|
||||
date: new Date().toISOString(), // Current date in ISO format
|
||||
paymentStatus: "Pending", // Default payment status
|
||||
};
|
||||
|
||||
const response = await fetch("http://localhost:3030/api/transaction/createTransaction", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(transactionData),
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
|
||||
if (result.success) {
|
||||
alert("Transaction created successfully!");
|
||||
} else {
|
||||
throw new Error(result.message || "Failed to create transaction");
|
||||
}
|
||||
|
||||
// Toggle contact options visibility
|
||||
setShowContactOptions(!showContactOptions);
|
||||
} catch (error) {
|
||||
console.error("Error creating transaction:", error);
|
||||
alert(`Error: ${error.message}`);
|
||||
}
|
||||
}}
|
||||
className="w-full bg-green-500 hover:bg-green-600 text-white font-medium py-3 px-4 mb-3"
|
||||
>
|
||||
Contact Seller
|
||||
|
||||
@@ -66,11 +66,12 @@ CREATE TABLE Review (
|
||||
|
||||
-- Transaction Entity (Many-to-One with User, Many-to-One with Product)
|
||||
CREATE TABLE Transaction (
|
||||
TransactionID INT PRIMARY KEY,
|
||||
TransactionID INT NOT NULL AUTO_INCREMENT,
|
||||
UserID INT,
|
||||
ProductID INT,
|
||||
Date DATETIME DEFAULT CURRENT_TIMESTAMP,
|
||||
PaymentStatus VARCHAR(50),
|
||||
PRIMARY KEY (TransactionID),
|
||||
FOREIGN KEY (UserID) REFERENCES User (UserID),
|
||||
FOREIGN KEY (ProductID) REFERENCES Product (ProductID)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user