import type { SubscribeInput } from '@gruperly/shared'; import { SubscribeInputSchema } from '@gruperly/shared'; import { Hono } from 'hono'; import { problemJson, resultJson, unauthorizedProblem } from '@/http/problem-details'; import { validate } from '@/http/validate'; import { Subscribe } from './use-case'; const route = new Hono(); // Returns `{ checkoutUrl }`: the browser navigates there to authorize the // subscription in Mercado Pago, the same way `/mp/connect` works. route.post('/subscribe', validate.json(SubscribeInputSchema), async (c) => { const user = c.get('user'); if (!user) return problemJson(c, unauthorizedProblem(c.req.path)); const input = c.req.valid('json') as SubscribeInput; const result = await new Subscribe().execute(user.id, input); return resultJson(c, result, { status: 201 }); }); export default route;