refactor: professional code quality audit
- Fix all TypeScript compilation errors (0 errors in src/) - Add try/catch error handling to ALL API routes (38 handlers) - Fix empty catch blocks (api-auth.ts now logs warnings) - Add aria-labels to all icon-only buttons (WCAG 2.1 AA) - Fix Prisma type mismatches (OR filter, Person.companyId, Estimate.projectId, Ticket.createdAt) - Fix webhook PATCH route (moved to [id]/route.ts) - Fix mobile-bottom-nav type safety - Fix KB route where-clause type - Fix test-mail banner null vs undefined - Fix task comment fetch: add cancellation + error toast - ESLint: 0 errors, 0 warnings - 175 files, 24.741 lines of code
This commit is contained in:
1 parent
969202764a
commit
fa8dd46571
175 files changed
+24741
-2
No files matched your search
Executable
+48
@@ -0,0 +1,48 @@
|
||||
import { NextResponse } from 'next/server'
|
||||
import { db } from '@/lib/db'
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
// GET /api/aos/licenses — issued licenses + asset/renewal register
|
||||
export async function GET() {
|
||||
try {
|
||||
const [licenses, assets] = await Promise.all([
|
||||
db.license.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
include: { company: true, activations: true },
|
||||
}),
|
||||
db.asset.findMany({ orderBy: { renewalDate: 'asc' } }),
|
||||
])
|
||||
|
||||
const activeLicenses = licenses.filter((l) => l.status === 'active').length
|
||||
const suspended = licenses.filter((l) => l.status === 'suspended').length
|
||||
const expired = licenses.filter((l) => l.status === 'expired').length
|
||||
const totalActivations = licenses.reduce((s, l) => s + l.activations.length, 0)
|
||||
|
||||
const expiringSoon = assets.filter((a) => {
|
||||
const days = (a.renewalDate.getTime() - Date.now()) / 86400000
|
||||
return days <= 30 && a.status !== 'expired'
|
||||
})
|
||||
const expiredAssets = assets.filter((a) => a.status === 'expired')
|
||||
const monthlyRebill = assets
|
||||
.filter((a) => a.rebill)
|
||||
.reduce((s, a) => s + (a.costCentsPerMonth ?? 0), 0)
|
||||
|
||||
return NextResponse.json({
|
||||
licenses,
|
||||
assets,
|
||||
stats: {
|
||||
activeLicenses,
|
||||
suspended,
|
||||
expired,
|
||||
totalActivations,
|
||||
expiringSoon: expiringSoon.length,
|
||||
expiredAssets: expiredAssets.length,
|
||||
monthlyRebill,
|
||||
},
|
||||
})
|
||||
} 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