File size: 965 Bytes
62c3fe0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 };