const {runSelectQuery, runQuery} = require('./queries'); async function checkExistingDemoRequest(name, email, product, demoDate, phone) { const checkQuery = ` SELECT * FROM demo_requests WHERE name = ? AND email = ? AND product = ? AND ABS(julianday(demo_date) - julianday(?)) <= 15 AND phone = ?; `; const results = await runSelectQuery(checkQuery, [name, email, product, demoDate, phone]); return results.length > 0; } // Insert demo request async function insertDemoRequest(name, email, company, product, demoDate, slot, phone, message) { const insertQuery = ` INSERT INTO demo_requests (date, time, name, email, company, product, demo_date, slot, phone, comments) VALUES (DATE("now"), TIME("now"), ?, ?, ?, ?, ?, ?, ?, ?); `; await runQuery(insertQuery, [name, email, company, product, demoDate, slot, phone, message]); } module.exports = { checkExistingDemoRequest, insertDemoRequest };