Files
accounted/app/api/clients/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

36 lines
1.5 KiB
TypeScript

import { NextResponse } from 'next/server'
import { withRouteContext } from '@/lib/api/with-route-context'
import { errorResponseFromCode } from '@/lib/errors/get-structured-error'
import { fetchClientOverview } from '@/lib/clients/fetch-client-overview'
/**
* GET /api/clients
*
* Byrå cockpit aggregate (WL-14): one row per client company on the caller's
* byrå team (teams.kind = 'byra') with the four at-a-glance signals: unbooked
* transaction count, unconsumed inbox document count, next deadline
* (status-engine semantics, 14-day ACTION_NEEDED window) and last booked
* (latest posted verifikat date). Rows arrive urgency-sorted: overdue
* deadlines first, then largest unbooked pile.
*
* Read-only across memberships (WL-09 read-first): RLS already allows these
* reads via user_company_ids(); the active company is untouched.
*
* Non-byrå users get 403 FORBIDDEN: the cockpit is byrå-exclusive in v1
* (multi-company self-users keep the company switcher).
*/
export const GET = withRouteContext('clients.list', async (_request, ctx) => {
const overview = await fetchClientOverview(ctx.supabase, ctx.user.id)
if (!overview) {
return errorResponseFromCode('FORBIDDEN', ctx.log, {
requestId: ctx.requestId,
reason: 'not a byrå team member',
messageSv: 'Klientlistan är endast tillgänglig för byråteam.',
messageEn: 'The client list is only available to byrå team members.',
})
}
return NextResponse.json({ data: overview })
})