import { type RejectReportedPayment, RejectReportedPaymentSchema } from '@gruperly/shared'; import { Hono } from 'hono'; import { problemJson, resultJson, unauthorizedProblem } from '@/http/problem-details'; import { validate } from '@/http/validate'; import { ReportedPayments } from './use-case'; const route = new Hono(); route.get('/reported', async (c) => { const user = c.get('user'); if (!user) return problemJson(c, unauthorizedProblem(c.req.path)); return resultJson(c, await new ReportedPayments().list(user.id)); }); route.get('/reported/:reportId/receipt', async (c) => { const user = c.get('user'); if (!user) return problemJson(c, unauthorizedProblem(c.req.path)); return resultJson(c, await new ReportedPayments().receiptUrl(user.id, c.req.param('reportId'))); }); route.post('/reported/:reportId/confirm', async (c) => { const user = c.get('user'); if (!user) return problemJson(c, unauthorizedProblem(c.req.path)); return resultJson(c, await new ReportedPayments().confirm(user.id, c.req.param('reportId'))); }); route.post('/reported/:reportId/reject', validate.json(RejectReportedPaymentSchema), async (c) => { const user = c.get('user'); if (!user) return problemJson(c, unauthorizedProblem(c.req.path)); const { reason } = c.req.valid('json') as RejectReportedPayment; return resultJson(c, await new ReportedPayments().reject(user.id, c.req.param('reportId'), reason ?? null)); }); route.post('/reported/:reportId/undo', async (c) => { const user = c.get('user'); if (!user) return problemJson(c, unauthorizedProblem(c.req.path)); return resultJson(c, await new ReportedPayments().undo(user.id, c.req.param('reportId'))); }); export default route;