* fix(import): SIE bulk-delete on service client + provider/reporting/banking fixes Rebuilt branch onto main as a single commit. - import: run SIE bulk-delete RPCs on the service client to escape the 8s statement_timeout; undo_sie_import now takes an explicit actor (p_user_id) so its owner/admin gate works when auth.uid() is NULL on the service client (migration 20260624120000) + pg-real regression test - providers: distinguish missing Fortnox license from expired connection; provider_consent_tokens PK regression test - reports: include unmapped BAS expense groups in the income statement - enable-banking: reconnect closed/expired bank sessions in place - bookkeeping: surface linked invoices as underlag on the verifikat view - scripts: track BL cleanup/diagnostic tooling; data files (*.csv) are git-ignored and consentId is now a required arg with no silent default Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(import): add Cache-Control header to journal entry references response --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
35 lines
1.2 KiB
TypeScript
35 lines
1.2 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'
|
|
|
|
/**
|
|
* 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 },
|
|
)
|