EverydayTech Platform - Developer Reference
Complete Source Code Documentation - All Applications
Loading...
Searching...
No Matches
test_api.js
Go to the documentation of this file.
1const express = require('express');
2const pool = require('./db');
3
4/**
5 *
6 */
7async function testAPI() {
8 try {
9 console.log('Testing database connection...');
10
11 // Test basic connection
12 const result = await pool.query('SELECT NOW()');
13 console.log('✓ Database connected at:', result.rows[0].now);
14
15 // Check if domains table exists
16 const tableCheck = await pool.query(`
17 SELECT EXISTS (
18 SELECT FROM information_schema.tables
19 WHERE table_name = 'domains'
20 )
21 `);
22 console.log('✓ Domains table exists:', tableCheck.rows[0].exists);
23
24 if (tableCheck.rows[0].exists) {
25 // Count domains
26 const count = await pool.query('SELECT COUNT(*) FROM domains');
27 console.log('✓ Total domains:', count.rows[0].count);
28
29 // Get sample
30 const domains = await pool.query('SELECT * FROM domains LIMIT 3');
31 console.log('✓ Sample domains:', domains.rows.length);
32 if (domains.rows.length > 0) {
33 console.table(domains.rows.map(d => ({
34 id: d.domain_id,
35 name: d.domain_name,
36 registrar: d.registrar,
37 tenant: d.tenant_id?.substring(0, 8)
38 })));
39 }
40 } else {
41 console.log('⚠ Domains table does not exist!');
42 console.log('Run the migration: psql -U rmm_user -d rmm_psa -f ../rmm-psa-database/2026_02_add_domains.sql');
43 }
44 } catch (error) {
45 console.error('✗ Error:', error.message);
46 } finally {
47 process.exit();
48 }
49}
50
51testAPI();