mirror of
https://github.com/freedbygrace/DynamoDNS.git
synced 2026-08-21 06:56:37 +00:00
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:
+33
-20
@@ -387,22 +387,27 @@ export class DatabaseStorage implements IStorage {
|
|||||||
// DNS Record management
|
// DNS Record management
|
||||||
async getDnsRecord(id: string): Promise<DnsRecord | undefined> {
|
async getDnsRecord(id: string): Promise<DnsRecord | undefined> {
|
||||||
try {
|
try {
|
||||||
// Use raw SQL to select only columns that actually exist in the database
|
console.log(`Getting DNS record with ID: ${id}`);
|
||||||
const query = sql`
|
|
||||||
|
// Use direct PostgreSQL query for consistent results
|
||||||
|
const { pool } = await import('./db');
|
||||||
|
const queryText = `
|
||||||
SELECT
|
SELECT
|
||||||
id, domain_id, name, type, content, ttl, priority,
|
id, domain_id, name, type, content, ttl, priority,
|
||||||
provider_record_id, is_active, auto_update, notes, last_updated, created_at
|
provider_record_id, is_active, auto_update, notes, last_updated, created_at
|
||||||
FROM dns_records
|
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;
|
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
|
// Map the result to match our schema expectations
|
||||||
return {
|
return {
|
||||||
@@ -429,24 +434,24 @@ export class DatabaseStorage implements IStorage {
|
|||||||
|
|
||||||
async getDnsRecordsByDomain(domainId: string): Promise<DnsRecord[]> {
|
async getDnsRecordsByDomain(domainId: string): Promise<DnsRecord[]> {
|
||||||
try {
|
try {
|
||||||
// Use raw SQL to select only columns that actually exist in the database
|
console.log(`Getting DNS records for domain: ${domainId}`);
|
||||||
const query = sql`
|
|
||||||
|
// Use direct PostgreSQL query for consistent results
|
||||||
|
const { pool } = await import('./db');
|
||||||
|
const queryText = `
|
||||||
SELECT
|
SELECT
|
||||||
id, domain_id, name, type, content, ttl, priority,
|
id, domain_id, name, type, content, ttl, priority,
|
||||||
provider_record_id, is_active, auto_update, notes, last_updated, created_at
|
provider_record_id, is_active, auto_update, notes, last_updated, created_at
|
||||||
FROM dns_records
|
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(`Found ${result.rows.length} DNS records for domain ${domainId}`);
|
||||||
console.log("Unexpected result format:", result);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
// Map the results to match our schema expectations
|
// Map the results to match our schema expectations
|
||||||
return result.map(record => ({
|
const mappedRecords = result.rows.map(record => ({
|
||||||
id: record.id,
|
id: record.id,
|
||||||
domainId: record.domain_id,
|
domainId: record.domain_id,
|
||||||
name: record.name,
|
name: record.name,
|
||||||
@@ -462,6 +467,9 @@ export class DatabaseStorage implements IStorage {
|
|||||||
createdAt: record.created_at,
|
createdAt: record.created_at,
|
||||||
proxied: null // Add missing field for frontend compatibility
|
proxied: null // Add missing field for frontend compatibility
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
console.log("Mapped records:", JSON.stringify(mappedRecords, null, 2));
|
||||||
|
return mappedRecords;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error in getDnsRecordsByDomain:", error);
|
console.error("Error in getDnsRecordsByDomain:", error);
|
||||||
return [];
|
return [];
|
||||||
@@ -701,17 +709,22 @@ export class DatabaseStorage implements IStorage {
|
|||||||
|
|
||||||
async deleteDnsRecord(id: string): Promise<boolean> {
|
async deleteDnsRecord(id: string): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
// Use SQL template for explicit query
|
console.log(`Deleting DNS record with ID: ${id}`);
|
||||||
const query = sql`
|
|
||||||
|
// Use direct PostgreSQL query for consistent results
|
||||||
|
const { pool } = await import('./db');
|
||||||
|
const queryText = `
|
||||||
DELETE FROM dns_records
|
DELETE FROM dns_records
|
||||||
WHERE id = ${id}
|
WHERE id = $1
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const result = await db.execute(query);
|
const result = await pool.query(queryText, [id]);
|
||||||
|
|
||||||
// Check if any rows were deleted
|
// 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) {
|
} catch (error) {
|
||||||
console.error("Error in deleteDnsRecord:", error);
|
console.error("Error in deleteDnsRecord:", error);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
+6
-1
@@ -82,11 +82,16 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
|||||||
return res.status(400).json({ message: "Domain ID is required" });
|
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);
|
const records = await storage.getDnsRecordsByDomain(domainId);
|
||||||
|
console.log(`API endpoint: Retrieved ${records.length} DNS records from storage`);
|
||||||
res.json(records);
|
res.json(records);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching DNS records:", 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)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user