feat: middleware plan + route GET /plans/status — 59/59 tests verts
This commit is contained in:
parent
f4849571c4
commit
f71498668f
4 changed files with 211 additions and 0 deletions
31
src/routes/plans.ts
Normal file
31
src/routes/plans.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
import { Hono } from 'hono'
|
||||
import { authMiddleware } from '../middleware/auth'
|
||||
import type { AppVariables } from '../middleware/auth'
|
||||
import { getPlanPermissions, PLANS } from '../lib/access'
|
||||
|
||||
const plans = new Hono<{ Variables: AppVariables }>()
|
||||
|
||||
plans.get('/status', authMiddleware, (c) => {
|
||||
const profile = c.get('profile')
|
||||
const plan = profile.plan as 'free' | 'standard' | 'premium'
|
||||
const permissions = getPlanPermissions(plan)
|
||||
|
||||
const simulationsLifetime = PLANS[plan].simulations_lifetime
|
||||
const simulationsRemaining =
|
||||
simulationsLifetime === null
|
||||
? null
|
||||
: Math.max(0, simulationsLifetime - profile.simulations_used)
|
||||
|
||||
return c.json(
|
||||
{
|
||||
plan: profile.plan,
|
||||
permissions,
|
||||
simulations_used: profile.simulations_used,
|
||||
simulations_remaining: simulationsRemaining,
|
||||
plan_expires_at: profile.plan_expires_at,
|
||||
},
|
||||
200
|
||||
)
|
||||
})
|
||||
|
||||
export default plans
|
||||
Loading…
Add table
Add a link
Reference in a new issue