i-darrshan's picture
initial update of the vite site
62c3fe0
raw
history blame contribute delete
907 Bytes
const { runQuery, runSelectQuery } = require('./queries');
async function addSubscriber(email) {
try {
// Check if email exists
const results = await runSelectQuery('SELECT * FROM subscribers WHERE email = ?', [email]);
if (results.length > 0) {
console.log("Email already exists in subscribers");
return { status: 400, error: 'You have already subscribed!!' };
}
// Insert new subscriber
await runQuery(
'INSERT INTO subscribers (date, time, email) VALUES (DATE("now"), TIME("now"), ?)',
[email]
);
console.log('Subscriber added successfully');
return { status: 200, message: 'Subscriber added' };
} catch (error) {
console.error('Database error:', error);
return { status: 500, error: 'Failed to add subscriber' };
}
}
module.exports = { addSubscriber };