From 8e5eb54e021abf4ee385a67ed4ccd064f63cabfd Mon Sep 17 00:00:00 2001 From: Muhammad Ibrahim Date: Thu, 6 Nov 2025 22:16:35 +0000 Subject: [PATCH] fixed code quality --- backend/src/services/agentWs.js | 21 +++++++++++---------- backend/src/utils/timezone.js | 27 +++++---------------------- 2 files changed, 16 insertions(+), 32 deletions(-) diff --git a/backend/src/services/agentWs.js b/backend/src/services/agentWs.js index 3f61d82..939c6a0 100644 --- a/backend/src/services/agentWs.js +++ b/backend/src/services/agentWs.js @@ -49,12 +49,12 @@ function init(server, prismaClient) { // Accept the WebSocket connection for Bull Board wss.handleUpgrade(request, socket, head, (ws) => { ws.on("message", (message) => { - // Echo back for Bull Board WebSocket - try { - ws.send(message); - } catch (err) { - // Ignore send errors (connection may be closed) - } + // Echo back for Bull Board WebSocket + try { + ws.send(message); + } catch (_err) { + // Ignore send errors (connection may be closed) + } }); ws.on("error", (err) => { @@ -160,9 +160,7 @@ function init(server, prismaClient) { err.message?.includes("read ECONNRESET") ) { // Connection reset errors are common and expected - console.log( - `[agent-ws] connection reset for ${apiId}`, - ); + console.log(`[agent-ws] connection reset for ${apiId}`); } else { // Log other errors for debugging console.error( @@ -181,7 +179,10 @@ function init(server, prismaClient) { } // Try to close the connection gracefully if still open - if (ws.readyState === WebSocket.OPEN || ws.readyState === WebSocket.CONNECTING) { + if ( + ws.readyState === WebSocket.OPEN || + ws.readyState === WebSocket.CONNECTING + ) { try { ws.close(1000); // Normal closure } catch { diff --git a/backend/src/utils/timezone.js b/backend/src/utils/timezone.js index 8eb783a..3a5718d 100644 --- a/backend/src/utils/timezone.js +++ b/backend/src/utils/timezone.js @@ -1,6 +1,6 @@ /** * Timezone utility functions for consistent timestamp handling - * + * * This module provides timezone-aware timestamp functions that use * the TZ environment variable for consistent timezone handling across * the application. If TZ is not set, defaults to UTC. @@ -22,32 +22,16 @@ function get_timezone() { */ function get_current_time() { const tz = get_timezone(); - + // If UTC, use Date.now() which is always UTC if (tz === "UTC" || tz === "Etc/UTC") { return new Date(); } - + // For other timezones, we need to create a date string with timezone info // and parse it. This ensures the date represents the correct time in that timezone. - const now = new Date(); - const formatter = new Intl.DateTimeFormat("en-US", { - timeZone: tz, - year: "numeric", - month: "2-digit", - day: "2-digit", - hour: "2-digit", - minute: "2-digit", - second: "2-digit", - hour12: false, - }); - - const parts = formatter.formatToParts(now); - const date_str = `${parts.find((p) => p.type === "year").value}-${parts.find((p) => p.type === "month").value}-${parts.find((p) => p.type === "day").value}T${parts.find((p) => p.type === "hour").value}:${parts.find((p) => p.type === "minute").value}:${parts.find((p) => p.type === "second").value}`; - - // Create date in UTC, then adjust to represent the same moment in the target timezone - // This is a bit tricky - we'll use a simpler approach: store as UTC but display in timezone // For database storage, we always store UTC timestamps + // The timezone is primarily used for display purposes return new Date(); } @@ -88,7 +72,7 @@ function parse_date(date_string, fallback = null) { return fallback || get_current_time(); } return date; - } catch (error) { + } catch (_error) { return fallback || get_current_time(); } } @@ -121,4 +105,3 @@ module.exports = { parse_date, format_date_for_display, }; -