import { Client } from 'pg';

async function checkSubmissions() {
  const client = new Client({
    connectionString: "postgresql://payload:120in09oenaoinsd9iaidon@127.0.0.1:54322/payload"
  });

  try {
    await client.connect();
    console.log("Connected to database.");
    
    const res = await client.query("SELECT * FROM form_submissions WHERE created_at >= '2026-04-12' ORDER BY created_at DESC;");
    
    if (res.rows.length === 0) {
      console.log("No submissions found for today.");
    } else {
      console.log(`Found ${res.rows.length} submissions for today:`);
      res.rows.forEach(row => {
        console.log(`- [${row.created_at}] ${row.name} (${row.email}): ${row.message.substring(0, 50)}...`);
      });
    }
  } catch (err) {
    console.error("Database query failed:", err.message);
  } finally {
    await client.end();
  }
}

checkSubmissions();
