import { NextResponse } from 'next/server';

import { withAuth } from '@/lib/api/helpers';
import { errorResponse } from '@/lib/errors';
import { db } from '@/lib/db';
import { currencyRates } from '@/lib/db/schema/system';

export const GET = withAuth(async (_req, _ctx) => {
  try {
    const rates = await db.select().from(currencyRates).orderBy(currencyRates.baseCurrency);
    return NextResponse.json({ data: rates });
  } catch (error) {
    return errorResponse(error);
  }
});
