* 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
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { withRouteContext } from '@/lib/api/with-route-context'
|
|
import { closePeriod } from '@/lib/core/bookkeeping/period-service'
|
|
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
|
|
|
// Response shapes are legacy `{ error: string }` — kept for the year-end UI.
|
|
// closePeriod throws plain Errors for every refusal (period not found, drafts
|
|
// remaining, already closed); they all map to 400 as before.
|
|
export const POST = withRouteContext(
|
|
'period.close',
|
|
async (_request, ctx, { params }: { params: Promise<{ id: string }> }) => {
|
|
const { id } = await params
|
|
const { user, supabase, companyId } = ctx
|
|
|
|
try {
|
|
const period = await closePeriod(supabase, companyId, user.id, id)
|
|
return NextResponse.json({ data: period })
|
|
} catch (err) {
|
|
return NextResponse.json(
|
|
{ error: err instanceof Error ? getUserErrorMessage(err) : 'Failed to close period' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
},
|
|
{ requireWrite: true },
|
|
)
|