* 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
79 lines
2.3 KiB
TypeScript
79 lines
2.3 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'
|
|
|
|
/**
|
|
* GET /api/import/sie/[id]
|
|
* Get details of a specific SIE import
|
|
*/
|
|
export const GET = withRouteContext<{ params: Promise<{ id: string }> }>(
|
|
'sie_import.get',
|
|
async (_request, { supabase, companyId }, { params }) => {
|
|
const { id } = await params
|
|
|
|
const { data, error } = await supabase
|
|
.from('sie_imports')
|
|
.select('*')
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
.single()
|
|
|
|
if (error) {
|
|
return NextResponse.json({ error: getUserErrorMessage(error) }, { status: 500 })
|
|
}
|
|
|
|
if (!data) {
|
|
return NextResponse.json({ error: 'Import not found' }, { status: 404 })
|
|
}
|
|
|
|
return NextResponse.json({ data })
|
|
},
|
|
)
|
|
|
|
/**
|
|
* DELETE /api/import/sie/[id]
|
|
* Delete an import record.
|
|
*
|
|
* Only failed or pending imports can be deleted. Completed imports have created
|
|
* journal entries that are part of räkenskapsinformation: deleting the metadata
|
|
* without reversing entries would leave orphaned bookkeeping data, and deleting
|
|
* both is prohibited under BFL 7 kap (7-year retention).
|
|
*/
|
|
export const DELETE = withRouteContext<{ params: Promise<{ id: string }> }>(
|
|
'sie_import.delete',
|
|
async (_request, { supabase, companyId }, { params }) => {
|
|
const { id } = await params
|
|
|
|
// Check current status before deleting
|
|
const { data: importRecord } = await supabase
|
|
.from('sie_imports')
|
|
.select('status')
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
.single()
|
|
|
|
if (!importRecord) {
|
|
return NextResponse.json({ error: 'Import not found' }, { status: 404 })
|
|
}
|
|
|
|
if (importRecord.status === 'completed') {
|
|
return NextResponse.json({
|
|
error: 'Slutförd import kan inte raderas. Importerade verifikationer ingår i räkenskapsinformationen (BFL 7 kap).',
|
|
}, { status: 403 })
|
|
}
|
|
|
|
const { error } = await supabase
|
|
.from('sie_imports')
|
|
.delete()
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
|
|
if (error) {
|
|
return NextResponse.json({ error: getUserErrorMessage(error) }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ success: true })
|
|
},
|
|
{ requireWrite: true },
|
|
)
|