Files
accounted/app/api/documents/counts/route.ts
T
Jakob Wennberg d0c0d8a7d2 feat: UX improvements — nav, reports tabs, dashboard alerts, transaction hints, settings layout
- Move Reports to Finans nav group and auto-expand Övrigt on its pages
- Make report tabs horizontally scrollable with gradient fade on mobile
- Surface deadlines and alerts above the fold on dashboard
- Add dismissible categorization hint card on transactions page
- Split settings company form into 4 separate Cards for scannability
- Add monthly breakdown report, document upload zone, journal entry attachments
- Add batch category selector, receipt document linking, invoice form improvements

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-20 17:16:22 +01:00

56 lines
1.5 KiB
TypeScript

import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
/**
* GET /api/documents/counts?journal_entry_ids=id1,id2,...
* Returns attachment counts per journal entry ID.
* Max 50 IDs per request.
*/
export async function GET(request: Request) {
const supabase = await createClient()
const { data: { user } } = await supabase.auth.getUser()
if (!user) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const { searchParams } = new URL(request.url)
const idsParam = searchParams.get('journal_entry_ids')
if (!idsParam) {
return NextResponse.json({ error: 'journal_entry_ids is required' }, { status: 400 })
}
const ids = idsParam.split(',').filter(Boolean)
if (ids.length === 0) {
return NextResponse.json({ data: {} })
}
if (ids.length > 50) {
return NextResponse.json({ error: 'Maximum 50 IDs per request' }, { status: 400 })
}
const { data, error } = await supabase
.from('document_attachments')
.select('journal_entry_id')
.eq('user_id', user.id)
.eq('is_current_version', true)
.in('journal_entry_id', ids)
if (error) {
return NextResponse.json({ error: error.message }, { status: 500 })
}
// Group and count by journal_entry_id
const counts: Record<string, number> = {}
for (const row of data || []) {
if (row.journal_entry_id) {
counts[row.journal_entry_id] = (counts[row.journal_entry_id] || 0) + 1
}
}
return NextResponse.json({ data: counts })
}