fix: currency converter and auth apis

This commit is contained in:
Vasily Zubarev
2025-04-09 15:04:48 +02:00
parent d71c4834c1
commit 29a4ac4977
3 changed files with 33 additions and 19 deletions

View File

@@ -1,6 +1,6 @@
import { getSession } from "@/lib/auth"
import { PoorManCache } from "@/lib/cache"
import { format } from "date-fns"
import { format, isSameDay, subDays } from "date-fns"
import { NextRequest, NextResponse } from "next/server"
type HistoricRate = {
@@ -36,11 +36,17 @@ export async function GET(request: NextRequest) {
return NextResponse.json({ error: "Missing required parameters: from, to, date" }, { status: 400 })
}
const date = new Date(dateParam)
let date = new Date(dateParam)
if (isNaN(date.getTime())) {
return NextResponse.json({ error: "Invalid date format" }, { status: 400 })
}
// hack to get yesterday's rate if it's today
if (isSameDay(date, new Date())) {
date = subDays(date, 1)
}
const formattedDate = format(date, "yyyy-MM-dd")
// Check cache first