Files
accounted/app/api/reconciliation/accounts/route.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

33 lines
1.3 KiB
TypeScript

import { NextResponse } from 'next/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { listReconciliationAccounts } from '@/lib/reconciliation/service'
import { ISO_DATE_RE } from '@/lib/invariants'
const DATE = ISO_DATE_RE
/**
* GET /api/reconciliation/accounts
*
* The side list of the Avstämning page: every account with an outside truth
* and its status. Same service function the v1 API and the MCP resource use.
* ?date_from / ?date_to scope the bank bridge; ?with_status=false skips the
* per-account status reads when only the list is needed.
*/
export const GET = withRouteContext(
'reconciliation.accounts.list',
async (request, { supabase, companyId }) => {
const { searchParams } = new URL(request.url)
const dateFrom = searchParams.get('date_from') || undefined
const dateTo = searchParams.get('date_to') || undefined
if ((dateFrom && !DATE.test(dateFrom)) || (dateTo && !DATE.test(dateTo))) {
return NextResponse.json({ error: 'Ogiltigt datum' }, { status: 400 })
}
const accounts = await listReconciliationAccounts(supabase, companyId, {
windowFrom: dateFrom,
windowTo: dateTo,
withStatus: searchParams.get('with_status') !== 'false',
})
return NextResponse.json({ data: { accounts } })
},
)