Files
accounted/app/api/rot-rut/payout-requests/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.6 KiB
TypeScript

import { NextResponse } from 'next/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { errorResponse } from '@/lib/errors/get-structured-error'
/**
* GET /api/rot-rut/payout-requests
*
* Request history (all statuses), newest first, with per-invoice items.
*/
export const GET = withRouteContext('rot_rut.requests.list', async (request, ctx) => {
const { supabase, companyId, log, requestId } = ctx
const { searchParams } = new URL(request.url)
const typeFilter = searchParams.get('type')
// Explicit projections: the history list needs identifiers and amounts,
// not every column (and never customer ids through the invoice join).
let query = supabase
.from('rot_rut_payout_requests')
.select(
'id, name, deduction_type, status, requested_total, decided_total, file_name, file_document_id, ' +
'created_at, submitted_at, decided_at, settlement_journal_entry_id, ' +
'reclaim_journal_entry_id, reclaimed_at, skv_referensnummer, ' +
'items:rot_rut_payout_request_items(id, invoice_id, requested_amount, decided_amount, reclaimed_amount, ' +
'invoice:invoices(id, invoice_number, status, remaining_amount))',
)
.eq('company_id', companyId!)
.order('created_at', { ascending: false })
.limit(100)
if (typeFilter === 'rot' || typeFilter === 'rut') {
query = query.eq('deduction_type', typeFilter)
}
const { data, error } = await query
if (error) {
log.error('failed to list rot/rut payout requests', error)
return errorResponse(error, log, { requestId })
}
return NextResponse.json({ data })
})