diff --git a/apps/backend/src/modules/quotes/handlers/getPeakHours.ts b/apps/backend/src/modules/quotes/handlers/getPeakHours.ts index f63d57b..26907ed 100644 --- a/apps/backend/src/modules/quotes/handlers/getPeakHours.ts +++ b/apps/backend/src/modules/quotes/handlers/getPeakHours.ts @@ -2,7 +2,6 @@ import type { Context } from "hono"; import type { QuoteType } from "../../../generated/prisma/client"; import { cache } from "../../../lib/cache"; import { prisma } from "../../../lib/prisma"; -import { parseLocalDate, startOfNextLocalDay } from "../../../lib/utils"; const VALID_TYPES = ["BLUE", "BNA", "BELO"] as const; @@ -18,21 +17,7 @@ export async function getPeakHours(c: Context) { ); } - const type = rawType as QuoteType; - const startDateParam = c.req.query("startDate"); - const endDateParam = c.req.query("endDate"); - - const now = new Date(); - const startDate = startDateParam - ? parseLocalDate(startDateParam) - : new Date(now.getFullYear(), now.getMonth(), 1); - const endDate = endDateParam ? startOfNextLocalDay(endDateParam) : now; - - if (Number.isNaN(startDate.getTime()) || Number.isNaN(endDate.getTime())) { - return c.json({ error: "Invalid date format. Use ISO 8601." }, 400); - } - - const cacheKey = `quotes:peak-hours:${type}:${startDate.toISOString()}:${endDate.toISOString()}`; + const cacheKey = `quotes:peak-hours:${rawType}`; const cached = cache.get(cacheKey); if (cached) return c.json(cached); @@ -56,8 +41,6 @@ export async function getPeakHours(c: Context) { ) AS rn FROM "quotes_history" WHERE "type" = ${rawType}::"QuoteType" - AND "timeStamp" >= ${startDate}::timestamptz - AND "timeStamp" < ${endDate}::timestamptz ) SELECT peak_hour AS hour, @@ -75,8 +58,6 @@ export async function getPeakHours(c: Context) { SELECT COUNT(DISTINCT DATE("timeStamp"))::int AS count FROM "quotes_history" WHERE "type" = ${rawType}::"QuoteType" - AND "timeStamp" >= ${startDate}::timestamptz - AND "timeStamp" < ${endDate}::timestamptz `; const response = { diff --git a/apps/frontend/src/features/analysis/AnalysisPage.tsx b/apps/frontend/src/features/analysis/AnalysisPage.tsx index 3edc33c..183f7f6 100644 --- a/apps/frontend/src/features/analysis/AnalysisPage.tsx +++ b/apps/frontend/src/features/analysis/AnalysisPage.tsx @@ -101,11 +101,8 @@ export function AnalysisPage({ currency }: { currency: string }) { ); const { data: monthlyLastData } = useMonthlyLast(); - const { data: peakHoursData, isLoading: peakHoursLoading } = usePeakHours( - "BELO", - startDateStr, - endDateStr, - ); + const { data: peakHoursData, isLoading: peakHoursLoading } = + usePeakHours("BELO"); const chartData = useMemo(() => { if (!daily) return []; diff --git a/apps/frontend/src/lib/api.ts b/apps/frontend/src/lib/api.ts index 3d93a47..0a4ba95 100644 --- a/apps/frontend/src/lib/api.ts +++ b/apps/frontend/src/lib/api.ts @@ -122,13 +122,8 @@ export function getHistoricalMinMax(type: string): Promise { return fetcher(`/api/quotes/${type}/historical/min-max`); } -export function getPeakHours( - type: string, - startDate: string, - endDate: string, -): Promise { - const params = new URLSearchParams({ startDate, endDate }); - return fetcher(`/api/quotes/${type}/peak-hours?${params}`); +export function getPeakHours(type: string): Promise { + return fetcher(`/api/quotes/${type}/peak-hours`); } export type MonthlyLast = { diff --git a/apps/frontend/src/lib/queries.ts b/apps/frontend/src/lib/queries.ts index 60a7faa..9572b45 100644 --- a/apps/frontend/src/lib/queries.ts +++ b/apps/frontend/src/lib/queries.ts @@ -64,8 +64,8 @@ export const quoteKeys = { ["quotes", type, "daily", startDate, endDate] as const, historicalMinMax: (type: string) => ["quotes", type, "historicalMinMax"] as const, - peakHours: (type: string, startDate: string, endDate: string) => - ["quotes", type, "peakHours", startDate, endDate] as const, + peakHours: (type: string) => + ["quotes", type, "peakHours"] as const, }; export function useQuotes() { @@ -135,14 +135,10 @@ export function useHistoricalMinMax(type: string) { }); } -export function usePeakHours( - type: string, - startDate: string, - endDate: string, -) { +export function usePeakHours(type: string) { return useQuery({ - queryKey: quoteKeys.peakHours(type, startDate, endDate), - queryFn: () => getPeakHours(type, startDate, endDate), + queryKey: quoteKeys.peakHours(type), + queryFn: () => getPeakHours(type), staleTime: 30_000, }); }