const db = require('./config/database');

async function checkDevices() {
  try {
    const [rows] = await db.execute('SELECT * FROM devices');
    console.log('Devices in database:');
    console.table(rows);
    
    console.log('\nAPI Query Result:');
    const query = `
      SELECT 
        d.id,
        d.device_id as deviceId,
        d.type,
        d.status,
        d.battery_level as battery,
        DATE_FORMAT(d.last_update, '%i mins ago') as lastUpdate,
        d.imei_number,
        d.sim_number,
        d.model,
        d.manufacturer
      FROM devices d 
      WHERE d.school_id = 1
      ORDER BY d.created_at DESC
    `;
    
    const [apiRows] = await db.execute(query);
    console.table(apiRows);
    
  } catch (error) {
    console.error('Error:', error);
  } finally {
    process.exit(0);
  }
}

checkDevices();