18 lines
612 B
TypeScript
18 lines
612 B
TypeScript
import { db } from '../../utils/db';
|
|
import { requireUser } from '../../utils/auth';
|
|
import { getPlan } from '#shared/plans';
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const user = await requireUser(event);
|
|
const sub = await db.subscription.findUnique({ where: { userId: user.id } });
|
|
const plan = getPlan(sub?.plan);
|
|
const usedCalls = await db.auditLog.count({ where: { actorId: user.id } });
|
|
return {
|
|
plan: plan.id,
|
|
metrics: [
|
|
{ label: 'Seats', used: 1, limit: plan.limits.seats },
|
|
{ label: 'API calls', used: usedCalls, limit: plan.limits.apiCalls },
|
|
],
|
|
};
|
|
});
|