* refactor: optimize page loading and data fetching * fix: resolve recurring production runtime errors * feat: add MCP company and customer updates * fix: handle year-end tax adjustments * feat: harden annual report compliance * fix: expand invoice logo and font support * fix: sanitize API route error responses * fix: sanitize user-facing error messages * feat: persist onboarding and tax assessment notices * fix: reduce cloud backup audit churn * feat: refine invoice editor layout * fix: show saved tax adjustments in INK2 * fix: complete annual report API mappings * docs: record operational safeguards and decisions * fix: harden annual report review findings * fix: adjust column span for description based on VAT registration * New css class name
40 lines
1.8 KiB
TypeScript
40 lines
1.8 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { fetchAllRows } from '@/lib/supabase/fetch-all'
|
|
import { withRouteContext } from '@/lib/api/with-route-context'
|
|
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
|
|
|
/**
|
|
* GET /api/bookkeeping/accounts/reference
|
|
*
|
|
* Returns the company's chart-of-accounts activation status: one lightweight
|
|
* row per account it holds (active or not), shaped
|
|
* `{ account_number, is_active, is_system_account }`.
|
|
*
|
|
* The BAS catalog itself is static and already bundled into the client
|
|
* (lib/bookkeeping/bas-reference); the kontoplan UI merges this activation
|
|
* list against that bundled catalog to render the "BAS-katalog" tab. We
|
|
* deliberately do NOT re-send the full ~1,300-account catalog over the wire on
|
|
* every page load; the browser already has that payload.
|
|
*/
|
|
export const GET = withRouteContext('bookkeeping.accounts.reference', async (_request, ctx) => {
|
|
const { supabase, companyId } = ctx
|
|
|
|
// Paginated with a stable unique order: a full-BAS chart exceeds the
|
|
// 1000-row page size, and unordered .range() paging can duplicate or skip
|
|
// rows on page boundaries (see fetch-all.ts ordering invariant).
|
|
try {
|
|
const userAccounts = await fetchAllRows<{ account_number: string; is_active: boolean; is_system_account: boolean }>(({ from, to }) =>
|
|
supabase
|
|
.from('chart_of_accounts')
|
|
.select('account_number, is_active, is_system_account')
|
|
.eq('company_id', companyId)
|
|
.order('account_number', { ascending: true })
|
|
.range(from, to)
|
|
)
|
|
|
|
return NextResponse.json({ data: userAccounts })
|
|
} catch (error) {
|
|
return NextResponse.json({ error: error instanceof Error ? getUserErrorMessage(error) : 'Failed to fetch accounts' }, { status: 500 })
|
|
}
|
|
})
|