Files
accounted/app/api/import/sie/[id]/undo/route.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

40 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server'
import { undoSIEImport } from '@/lib/import/sie-import'
import { withRouteContext } from '@/lib/api/with-route-context'
import { errorResponseFromCode } from '@/lib/errors/get-structured-error'
// Hard-deleting a large import (thousands of audit-logged journal entries +
// cascading lines) can take well over the default function timeout. Match the
// SIE execute route so the serverless function doesn't kill the request first.
export const maxDuration = 300
/**
* DELETE /api/import/sie/[id]/undo
*
* Undo a completed SIE import: hard-deletes all journal entries created
* by the import (transaction vouchers + the opening_balance entry),
* detaches any user-attached documents, resets voucher_sequences, and
* marks the sie_imports row as 'undone'. Period must be open and not
* locked. Owner/admin only (enforced by the RPC).
*/
export const DELETE = withRouteContext(
'sie_import.undo',
async (_request, ctx, { params }: { params: Promise<{ id: string }> }) => {
const { id } = await params
const { supabase, companyId, user, log, requestId } = ctx
const opLog = log.child({ sieImportId: id })
const result = await undoSIEImport(supabase, companyId!, id, user.id)
if (!result.success) {
return errorResponseFromCode('SIE_UNDO_FAILED', opLog, {
requestId,
details: { reason: result.error },
})
}
return NextResponse.json({ success: true, deletedEntries: result.deletedEntries })
},
{ requireWrite: true },
)