* 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
85 lines
2.7 KiB
TypeScript
85 lines
2.7 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'
|
|
|
|
/**
|
|
* POST /api/transactions/[id]/ignore
|
|
*
|
|
* Mark a bank transaction as ignored so it stops surfacing in the bank
|
|
* reconciliation view (and other "to book" funnels) without creating a
|
|
* verifikation. Use case: tiny ränteintäkter, rounding noise, opening-balance
|
|
* artefacts: anything the user wants off the unmatched list but doesn't want
|
|
* to fabricate a journal entry for.
|
|
*
|
|
* Refuses when the transaction is already booked; once a verifikation exists,
|
|
* the proper way to revisit it is /uncategorize (storno).
|
|
*/
|
|
export const POST = withRouteContext<{ params: Promise<{ id: string }> }>(
|
|
'transaction.ignore',
|
|
async (_request, { supabase, companyId }, { params }) => {
|
|
const { id } = await params
|
|
|
|
const { data: transaction, error: fetchError } = await supabase
|
|
.from('transactions')
|
|
.select('id, journal_entry_id, is_ignored')
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
.single()
|
|
|
|
if (fetchError || !transaction) {
|
|
return NextResponse.json({ error: 'Transaction not found' }, { status: 404 })
|
|
}
|
|
|
|
if (transaction.journal_entry_id) {
|
|
return NextResponse.json(
|
|
{ error: 'Transaktionen är redan bokförd: använd Avmatcha eller backa verifikationen för att ändra status.' },
|
|
{ status: 409 }
|
|
)
|
|
}
|
|
|
|
if (transaction.is_ignored) {
|
|
return NextResponse.json({ success: true, already_ignored: true })
|
|
}
|
|
|
|
const { error: updateError } = await supabase
|
|
.from('transactions')
|
|
.update({ is_ignored: true })
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
|
|
if (updateError) {
|
|
return NextResponse.json({ error: getUserErrorMessage(updateError) }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ success: true })
|
|
},
|
|
{ requireWrite: true },
|
|
)
|
|
|
|
/**
|
|
* DELETE /api/transactions/[id]/ignore
|
|
*
|
|
* Reverse a previous ignore. The row comes back into the unmatched list with
|
|
* no further side effects: we never created a verifikation, so there's
|
|
* nothing to storno.
|
|
*/
|
|
export const DELETE = withRouteContext<{ params: Promise<{ id: string }> }>(
|
|
'transaction.unignore',
|
|
async (_request, { supabase, companyId }, { params }) => {
|
|
const { id } = await params
|
|
|
|
const { error: updateError } = await supabase
|
|
.from('transactions')
|
|
.update({ is_ignored: false })
|
|
.eq('id', id)
|
|
.eq('company_id', companyId)
|
|
|
|
if (updateError) {
|
|
return NextResponse.json({ error: getUserErrorMessage(updateError) }, { status: 500 })
|
|
}
|
|
|
|
return NextResponse.json({ success: true })
|
|
},
|
|
{ requireWrite: true },
|
|
)
|