TypeScriptAuthorizationDifficulty 1/3
// app/api/accounts/[accountId]/balance/route.ts
import { NextRequest, NextResponse } from "next/server";
import { getSession } from "@/lib/session";
import { db } from "@/lib/db";
export async function GET(
_req: NextRequest,
{ params }: { params: Promise<{ accountId: string }> },
) {
const session = await getSession();
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { accountId } = await params;
const account = await db.account.findUnique({
where: { id: accountId },
select: { balanceMinor: true, currency: true },
});
if (!account) {
return NextResponse.json({ error: "Account not found" }, { status: 404 });
}
return NextResponse.json(account);
}