* 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.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { NextResponse } from 'next/server'
|
|
import { withRouteContext } from '@/lib/api/with-route-context'
|
|
import { lookupTaxFromApi, TaxTableUnavailableError } from '@/lib/salary/tax-tables'
|
|
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
|
|
|
export const GET = withRouteContext('salary.tax_tables.lookup', async (request) => {
|
|
const { searchParams } = new URL(request.url)
|
|
const year = parseInt(searchParams.get('year') || new Date().getFullYear().toString())
|
|
const tableNumber = parseInt(searchParams.get('table') || '0')
|
|
const column = parseInt(searchParams.get('column') || '1')
|
|
const income = parseFloat(searchParams.get('income') || '0')
|
|
|
|
if (!tableNumber || tableNumber < 29 || tableNumber > 42) {
|
|
return NextResponse.json({ error: 'Skattetabell måste vara 29-42' }, { status: 400 })
|
|
}
|
|
|
|
try {
|
|
const { taxAmount, source } = await lookupTaxFromApi(tableNumber, column, income, year)
|
|
return NextResponse.json({
|
|
data: {
|
|
year,
|
|
tableNumber,
|
|
column,
|
|
income,
|
|
taxAmount,
|
|
source: source === 'api' ? 'skatteverket_api' : 'local_fallback',
|
|
},
|
|
})
|
|
} catch (err) {
|
|
if (err instanceof TaxTableUnavailableError) {
|
|
return NextResponse.json({ error: getUserErrorMessage(err) }, { status: 503 })
|
|
}
|
|
throw err
|
|
}
|
|
})
|