Em dashes (—) and en dashes (–) had spread across comments, docs, tests, and a few UI strings, reading as AI-generated boilerplate rather than house style. Replaced each with punctuation matching its context: colon for explanatory clauses, comma for asides, plain hyphen for numeric/legal ranges (e.g. "21-23§"), "to"/"till" for date ranges, parentheses for paired-dash asides. messages/en.json and messages/sv.json were fixed by hand together to keep sv/en in sync. Left untouched where the dash is the functional subject rather than decorative punctuation: date-range-parser.ts's separator regex, charset-repair.ts's CP1252 byte-mapping table (and its test), the SIE encoding mojibake docs, generic-csv.ts's minus-sign normalizer, the agent system-prompt files that already instruct against em dashes, and a golden iXBRL test fixture compared byte-for-byte. Also fixes two bugs surfaced along the way: an off-by-one in ApiKeysPanel's scope-label split (a leftover from an earlier partial pass), and a charset-repair test that had lost the literal en-dash it exists to verify. Regenerated the agent atom seed migration (skills:generate) since 27 SKILL.md files changed. Added a CLAUDE.md rule against em/en dashes, with an explicit carve-out for the functional-dash cases above. Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
63 lines
2.5 KiB
TypeScript
63 lines
2.5 KiB
TypeScript
/**
|
|
* GET /api/transactions/[id]/duplicate-payment-check
|
|
*
|
|
* Proactive check used by the InvoiceMatchDialog: returns the candidate
|
|
* verifikation that already books this bank transaction, or null if no
|
|
* duplicate is detected. Lets the UI display the warning panel without
|
|
* needing to first submit a doomed match.
|
|
*
|
|
* Same detector as the match-invoice route's pre-flight, so what you see
|
|
* here matches what the POST would refuse.
|
|
*/
|
|
import { NextResponse } from 'next/server'
|
|
import { withRouteContext } from '@/lib/api/with-route-context'
|
|
import { errorResponseFromCode } from '@/lib/errors/get-structured-error'
|
|
import { detectDuplicatePaymentVoucher } from '@/lib/invoices/duplicate-payment-detection'
|
|
|
|
export const GET = withRouteContext(
|
|
'transaction.duplicate_payment_check',
|
|
async (_request, ctx, { params }: { params: Promise<{ id: string }> }) => {
|
|
const { id: transactionId } = await params
|
|
const { supabase, companyId, log, requestId } = ctx
|
|
|
|
// Membership is enforced by withRouteContext (see its docstring): the
|
|
// resolved companyId is always a company the caller is a member of, so
|
|
// intra-company multi-user visibility of transaction metadata here is
|
|
// the intended tenancy model. The selected column set is intentionally
|
|
// narrow (id, date, amount, journal_entry_id) so this endpoint cannot
|
|
// leak description / counterparty fields that aren't required to
|
|
// surface a duplicate-payment candidate. GDPR Art.5(1)(c)/(f).
|
|
const { data: transaction, error } = await supabase
|
|
.from('transactions')
|
|
.select('id, date, amount, journal_entry_id')
|
|
.eq('id', transactionId)
|
|
.eq('company_id', companyId)
|
|
.single()
|
|
|
|
if (error || !transaction) {
|
|
return errorResponseFromCode('TX_CATEGORIZE_TX_NOT_FOUND', log, { requestId })
|
|
}
|
|
|
|
// Already linked → no possible duplicate to surface.
|
|
if (transaction.journal_entry_id) {
|
|
return NextResponse.json({ candidate: null })
|
|
}
|
|
|
|
try {
|
|
const candidate = await detectDuplicatePaymentVoucher(supabase, {
|
|
companyId: companyId!,
|
|
transactionId,
|
|
transactionDate: transaction.date,
|
|
transactionAmount: transaction.amount,
|
|
})
|
|
return NextResponse.json({ candidate })
|
|
} catch (err) {
|
|
log.warn('duplicate-payment-voucher detection failed', err as Error)
|
|
// Fail-open: returning null preserves current UX. The POST still
|
|
// runs its own check, so a missed pre-flight doesn't allow a
|
|
// duplicate booking.
|
|
return NextResponse.json({ candidate: null })
|
|
}
|
|
},
|
|
)
|