Files
accounted/components/transactions/detach-underlag.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

29 lines
1.2 KiB
TypeScript

import { getErrorMessage } from '@/lib/errors/get-error-message'
/**
* Gate for the "Ta bort underlag" affordance on a transaction row (#2132).
*
* Mirrors DELETE /api/transactions/[id]/attach-document: once the document has
* propagated onto a verifikation the route answers 409 (BFL 5 kap 6 §), so the
* UI only offers the action to writers, on unbooked rows that carry a pin.
*/
export function canDetachDocument(input: {
isBooked: boolean
canWrite: boolean
documentId: string | null | undefined
hasHandler: boolean
}): boolean {
return !input.isBooked && input.canWrite && !!input.documentId && input.hasHandler
}
/**
* Toast description for a failed detach. A 409 carries the route's own
* Swedish explanation (the doc is already räkenskapsinformation): surface it
* verbatim. Everything else maps through the shared error translator.
*/
export function resolveDetachErrorMessage(status: number, body: unknown): string {
const error = (body as { error?: unknown } | null | undefined)?.error
if (status === 409 && typeof error === 'string' && error.trim()) return error
return getErrorMessage(body, { context: 'transaction', statusCode: status })
}