Fix: Newly created DNS records not appearing in the display table. Improved database query consistency and error handling.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9111ef36-26c8-4085-84ca-a35dc1fec1b5
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7083d608-d6d3-4a6a-9a27-6286c5109627/c498368e-812e-4074-a2b0-5b1c897c3ee4.jpg
This commit is contained in:
alphaeusmote
2025-04-11 02:38:58 +00:00
parent 344a433528
commit 0d8702d49e
2 changed files with 39 additions and 21 deletions
+33 -20
View File
@@ -387,22 +387,27 @@ export class DatabaseStorage implements IStorage {
// DNS Record management
async getDnsRecord(id: string): Promise<DnsRecord | undefined> {
try {
// Use raw SQL to select only columns that actually exist in the database
const query = sql`
console.log(`Getting DNS record with ID: ${id}`);
// Use direct PostgreSQL query for consistent results
const { pool } = await import('./db');
const queryText = `
SELECT
id, domain_id, name, type, content, ttl, priority,
provider_record_id, is_active, auto_update, notes, last_updated, created_at
FROM dns_records
WHERE id = ${id}
WHERE id = $1
`;
const result = await db.execute(query);
const result = await pool.query(queryText, [id]);
if (!Array.isArray(result) || result.length === 0) {
if (!result.rows || result.rows.length === 0) {
console.log(`DNS record with ID ${id} not found`);
return undefined;
}
const record = result[0];
const record = result.rows[0];
console.log(`Found DNS record:`, record);
// Map the result to match our schema expectations
return {
@@ -429,24 +434,24 @@ export class DatabaseStorage implements IStorage {
async getDnsRecordsByDomain(domainId: string): Promise<DnsRecord[]> {
try {
// Use raw SQL to select only columns that actually exist in the database
const query = sql`
console.log(`Getting DNS records for domain: ${domainId}`);
// Use direct PostgreSQL query for consistent results
const { pool } = await import('./db');
const queryText = `
SELECT
id, domain_id, name, type, content, ttl, priority,
provider_record_id, is_active, auto_update, notes, last_updated, created_at
FROM dns_records
WHERE domain_id = ${domainId}
WHERE domain_id = $1
`;
const result = await db.execute(query);
const result = await pool.query(queryText, [domainId]);
if (!Array.isArray(result)) {
console.log("Unexpected result format:", result);
return [];
}
console.log(`Found ${result.rows.length} DNS records for domain ${domainId}`);
// Map the results to match our schema expectations
return result.map(record => ({
const mappedRecords = result.rows.map(record => ({
id: record.id,
domainId: record.domain_id,
name: record.name,
@@ -462,6 +467,9 @@ export class DatabaseStorage implements IStorage {
createdAt: record.created_at,
proxied: null // Add missing field for frontend compatibility
}));
console.log("Mapped records:", JSON.stringify(mappedRecords, null, 2));
return mappedRecords;
} catch (error) {
console.error("Error in getDnsRecordsByDomain:", error);
return [];
@@ -701,17 +709,22 @@ export class DatabaseStorage implements IStorage {
async deleteDnsRecord(id: string): Promise<boolean> {
try {
// Use SQL template for explicit query
const query = sql`
console.log(`Deleting DNS record with ID: ${id}`);
// Use direct PostgreSQL query for consistent results
const { pool } = await import('./db');
const queryText = `
DELETE FROM dns_records
WHERE id = ${id}
WHERE id = $1
RETURNING id
`;
const result = await db.execute(query);
const result = await pool.query(queryText, [id]);
// Check if any rows were deleted
return Array.isArray(result) && result.length > 0;
const success = result.rows && result.rows.length > 0;
console.log(`Delete operation result for DNS record ${id}: ${success ? 'Success' : 'Not found'}`);
return success;
} catch (error) {
console.error("Error in deleteDnsRecord:", error);
return false;
+6 -1
View File
@@ -82,11 +82,16 @@ export async function registerRoutes(app: Express): Promise<Server> {
return res.status(400).json({ message: "Domain ID is required" });
}
console.log(`API endpoint: Fetching DNS records for domain: ${domainId}`);
const records = await storage.getDnsRecordsByDomain(domainId);
console.log(`API endpoint: Retrieved ${records.length} DNS records from storage`);
res.json(records);
} catch (error) {
console.error("Error fetching DNS records:", error);
res.status(500).json({ message: "Internal server error" });
res.status(500).json({
message: "Failed to fetch DNS records",
error: error instanceof Error ? error.message : String(error)
});
}
});