import { type ConfirmRecoveryEmail as ConfirmRecoveryEmailInput, ConfirmRecoveryEmailSchema, type SetRecoveryEmail as SetRecoveryEmailInput, SetRecoveryEmailSchema, } from '@gruperly/shared'; import { Hono } from 'hono'; import type { BackendEnv } from '@/http/env'; import { problemJson, resultJson } from '@/http/problem-details'; import { validate } from '@/http/validate'; import { currentStudent, studentSession } from '../../middleware'; import { GetStudentMe } from '../me/use-case'; import { ConfirmRecoveryEmail, RemoveRecoveryEmail, SetRecoveryEmail } from './use-case'; const route = new Hono(); route.put('/me/recovery-email', studentSession, validate.json(SetRecoveryEmailSchema), async (c) => { const { accountId } = currentStudent(c); const { email } = c.req.valid('json') as SetRecoveryEmailInput; const result = await new SetRecoveryEmail().execute(accountId, email); if (!result.ok) return problemJson(c, result.error); return resultJson(c, await new GetStudentMe().execute(accountId)); }); route.delete('/me/recovery-email', studentSession, async (c) => { const { accountId } = currentStudent(c); await new RemoveRecoveryEmail().execute(accountId); return resultJson(c, await new GetStudentMe().execute(accountId)); }); route.post('/recovery-email/confirm', validate.json(ConfirmRecoveryEmailSchema), async (c) => { const { token } = c.req.valid('json') as ConfirmRecoveryEmailInput; return resultJson(c, await new ConfirmRecoveryEmail().execute(token)); }); export default route;