Files
accounted/app/api/bookkeeping/journal-entries/[id]/notes/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

43 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { z } from 'zod'
import { validateBody } from '@/lib/api/validate'
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
const UpdateNotesSchema = z.object({
notes: z.string().max(2000).nullable(),
})
// Notes are annotation metadata alongside the verifikat (not räkenskaps-
// information) — the immutability trigger governs what may change on posted
// entries; this route just scopes and validates.
export const PATCH = withRouteContext<{ params: Promise<{ id: string }> }>(
'bookkeeping.journal_entry.notes',
async (request, { supabase, companyId }, { params }) => {
const { id } = await params
const result = await validateBody(request, UpdateNotesSchema)
if (!result.success) return result.response
const { data, error } = await supabase
.from('journal_entries')
.update({ notes: result.data.notes })
.eq('id', id)
.eq('company_id', companyId)
.select('id')
.maybeSingle()
if (error) {
return NextResponse.json({ error: getUserErrorMessage(error) }, { status: 400 })
}
// Zero rows = the entry doesn't exist in this company — report it instead
// of a phantom success.
if (!data) {
return NextResponse.json({ error: 'Verifikationen hittades inte.' }, { status: 404 })
}
return NextResponse.json({ data: { updated: true } })
},
{ requireWrite: true },
)