dcfa2f8c8d
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
import { exportTransactions } from "@/features/transactions/service";
|
|
import { tr } from "@/i18n/tr";
|
|
import { getHouseholdContext } from "@/lib/dal";
|
|
import { csvMoney, toCsv } from "@/shared/csv";
|
|
import { todayIstanbul } from "@/shared/dates";
|
|
import { formatDate } from "@/shared/format";
|
|
import { transactionFilterSchema } from "@/shared/schemas/transaction";
|
|
|
|
/** GET /islemler/disa-aktar?…filtreler → CSV (listedeki filtrelerle, sayfalama yok). */
|
|
export async function GET(request: Request) {
|
|
const ctx = await getHouseholdContext();
|
|
if (!ctx?.household) return new Response(tr.common.unauthorized, { status: 401 });
|
|
const params = Object.fromEntries(new URL(request.url).searchParams);
|
|
const filters = transactionFilterSchema.parse(params);
|
|
const rows = await exportTransactions(ctx.user.id, ctx.household.id, filters);
|
|
if (!rows) return new Response(tr.common.unauthorized, { status: 403 });
|
|
|
|
const t = tr.transactions;
|
|
const csv = toCsv(
|
|
t.csv.header,
|
|
rows.map((r) => [
|
|
r.no,
|
|
formatDate(`${r.date}T12:00:00+03:00`),
|
|
t.types[r.type],
|
|
t.statuses[r.status],
|
|
r.account,
|
|
r.toAccount,
|
|
r.category,
|
|
r.payee,
|
|
r.description,
|
|
r.note,
|
|
r.tags,
|
|
csvMoney(r.amountMinor),
|
|
r.createdBy,
|
|
]),
|
|
);
|
|
return new Response(csv, {
|
|
headers: {
|
|
"Content-Type": "text/csv; charset=utf-8",
|
|
"Content-Disposition": `attachment; filename="${t.csv.filename(todayIstanbul())}"`,
|
|
"Cache-Control": "no-store",
|
|
},
|
|
});
|
|
}
|