/opt/canhelp/apps/api/src/routes
Edit: /opt/canhelp/apps/api/src/routes/plans.ts (1352B)
import { Hono } from 'hono'
import { eq, and, asc } from 'drizzle-orm'
import { db } from '../db.js'
import { plans } from '@canhelp/db'
import { requireAuth, type AuthVariables } from '../middleware/auth.js'
import { getDailyUsageSummary } from '../lib/daily-limits.js'
const app = new Hono<{ Variables: AuthVariables }>()
// GET /plans — public list of active plans (for pricing page)
// Tariffs are unified (no customer/specialist split), so the optional
// ?role / ?audience query params are accepted for backward compatibility
// but no longer filter the result — every active plan is returned.
app.get('/', async (c) => {
const rows = await db
.select()
.from(plans)
.where(eq(plans.isActive, true))
.orderBy(asc(plans.order), asc(plans.name))
return c.json(rows)
})
// GET /plans/daily-usage — current user's daily usage summary
app.get('/daily-usage', requireAuth, async (c) => {
const user = c.get('user')
const summary = await getDailyUsageSummary(user.id)
return c.json(summary)
})
// GET /plans/:id — single plan details
app.get('/:id', async (c) => {
const [plan] = await db
.select()
.from(plans)
.where(and(eq(plans.id, c.req.param('id')), eq(plans.isActive, true)))
if (!plan) {
return c.json({ error: 'Plan not found' }, 404)
}
return c.json(plan)
})
export default app