a6c0f3de-eeb0-4d76-a57f-f600dd133c06
This commit is contained in:
1 parent
2aa3496a90
commit
762f3d7373
141 files changed
+4485
-69
No files matched your search
@@ -0,0 +1,42 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { db } from '@/lib/db'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
// GET /api/aos/agency
|
||||
// Returns all agency applications + approved agencies. Admin-only in practice
|
||||
// (no scope check here because AOS is single-tenant dev mode).
|
||||
export async function GET() {
|
||||
try {
|
||||
const [applications, agencies] = await Promise.all([
|
||||
db.agencyApplication.findMany({
|
||||
orderBy: { appliedAt: 'desc' },
|
||||
include: { company: true },
|
||||
}),
|
||||
db.company.findMany({
|
||||
where: { isAgency: true, agencyStatus: 'approved' },
|
||||
orderBy: { agencyApprovedAt: 'desc' },
|
||||
include: {
|
||||
agencyClients: { select: { id: true, name: true, email: true } },
|
||||
_count: { select: { agencyClients: true, licenses: true } },
|
||||
},
|
||||
}),
|
||||
])
|
||||
|
||||
const pending = applications.filter((a) => a.status === 'pending')
|
||||
const reviewed = applications.filter((a) => a.status !== 'pending')
|
||||
|
||||
return NextResponse.json({
|
||||
applications: { pending, reviewed },
|
||||
agencies,
|
||||
stats: {
|
||||
pending: pending.length,
|
||||
approved: agencies.length,
|
||||
totalApplications: applications.length,
|
||||
},
|
||||
})
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : 'internal server error'
|
||||
return NextResponse.json({ error: msg }, { status: 500 })
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user