* 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
36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { withRouteContext } from '@/lib/api/with-route-context'
|
|
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
|
|
|
export const GET = withRouteContext(
|
|
'period.entry_count',
|
|
async (_request, ctx, { params }: { params: Promise<{ id: string }> }) => {
|
|
const { id } = await params
|
|
const { supabase, companyId } = ctx
|
|
|
|
const { data: period, error: fetchError } = await supabase
|
|
.from('fiscal_periods')
|
|
.select('id')
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
.maybeSingle()
|
|
|
|
if (fetchError || !period) {
|
|
return NextResponse.json({ error: 'Räkenskapsår hittades inte' }, { status: 404 })
|
|
}
|
|
|
|
const { count, error: countError } = await supabase
|
|
.from('journal_entries')
|
|
.select('id', { count: 'exact', head: true })
|
|
.eq('company_id', companyId)
|
|
.eq('fiscal_period_id', id)
|
|
.in('status', ['posted', 'reversed'])
|
|
|
|
if (countError) {
|
|
return NextResponse.json({ error: getUserErrorMessage(countError) }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ data: { posted_count: count ?? 0 } })
|
|
},
|
|
)
|