- Nuevo modelo `Person` (`people`): contacto y notas por profe, con teléfono único (índice parcial `people_owner_phone_key`). `Attendee` pasa a ser la membresía (`group_id` + `person_id`, único por grupo). - La cuenta de la app de alumnos se vincula a la persona (`student_account_people`): una sola cuenta ve todos sus grupos. - Migración unifica attendees del mismo profe y teléfono, y fusiona sus cuentas de alumno (conserva la usada más recientemente). - `POST /groups/:gid/attendees/:aid/add-to-group` y `GET /people/lookup` para detectar personas existentes al cargar; el alta responde `409 person_exists` y acepta `personId`. Bulk, lista de espera y preinscripciones vinculan solas. - El límite del plan cuenta personas con al menos un grupo activo. - Web: "Agregar a otro grupo", sección "También está en" en la ficha y aviso "Ya tenés a esta persona" en el alta individual. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
84 lines
3.1 KiB
TypeScript
84 lines
3.1 KiB
TypeScript
import { Hono } from 'hono';
|
|
import type { BackendEnv } from '@/http/env';
|
|
import {
|
|
internalServerErrorProblem,
|
|
notFoundProblem,
|
|
problemJson,
|
|
} from '@/http/problem-details';
|
|
import { requestIdMiddleware } from '@/http/request-id';
|
|
import { requestLoggerMiddleware } from '@/http/request-logger';
|
|
import { corsMiddleware, securityHeadersMiddleware } from '@/http/security-headers';
|
|
import { sessionAuthMiddleware } from '@/http/session-auth';
|
|
import { logger } from '@/logger';
|
|
import { adminRoutes } from './modules/admin';
|
|
import {
|
|
groupsRiskOverviewRoute,
|
|
studentStatusRoutes,
|
|
} from './modules/analytics';
|
|
import { attendeesRoutes } from './modules/attendees';
|
|
import { attentionRoutes } from './modules/attention';
|
|
import { authRoutes } from './modules/auth';
|
|
import { billingRoutes, planReadOnlyMiddleware } from './modules/billing';
|
|
import { classesRoutes } from './modules/classes';
|
|
import { groupsRoutes } from './modules/groups';
|
|
import { healthCheckRoutes } from './modules/health-check';
|
|
import { homeRoutes } from './modules/home';
|
|
import { invitationsRoutes } from './modules/invitations';
|
|
import { mpRoutes } from './modules/mp';
|
|
import { onboardingRoutes } from './modules/onboarding';
|
|
import { paymentsRoutes } from './modules/payments';
|
|
import { peopleRoutes } from './modules/people';
|
|
import { studentPortalRoutes } from './modules/student-portal';
|
|
import { waitlistRoutes } from './modules/waitlist';
|
|
import { whatsappRoutes } from './modules/whatsapp';
|
|
|
|
const app = new Hono<BackendEnv>();
|
|
|
|
app.use('*', corsMiddleware);
|
|
app.use('*', securityHeadersMiddleware);
|
|
app.use('*', requestIdMiddleware);
|
|
app.use('*', requestLoggerMiddleware);
|
|
|
|
app.get('/', (c) => c.json({ name: 'Gruperly API', status: 'ok' }));
|
|
|
|
const api = app.basePath('/api/v1');
|
|
|
|
api.use('*', sessionAuthMiddleware);
|
|
|
|
// Read-only accounts (Free over its limits) cannot write domain data. Billing,
|
|
// onboarding and the MP/WhatsApp links stay open: that is how they get out of it.
|
|
const planReadOnly = planReadOnlyMiddleware();
|
|
for (const prefix of ['/groups', '/attendees', '/payments', '/classes', '/students', '/waitlist']) {
|
|
api.use(`${prefix}/*`, planReadOnly);
|
|
}
|
|
|
|
api.route('/admin', adminRoutes);
|
|
api.route('/auth', authRoutes);
|
|
api.route('/health', healthCheckRoutes);
|
|
api.route('/invitations', invitationsRoutes);
|
|
api.route('/groups', groupsRoutes);
|
|
api.route('/home', homeRoutes);
|
|
api.route('/onboarding', onboardingRoutes);
|
|
api.route('/mp', mpRoutes);
|
|
api.route('/whatsapp', whatsappRoutes);
|
|
api.route('/attendees', attendeesRoutes);
|
|
api.route('/payments', paymentsRoutes);
|
|
api.route('/billing', billingRoutes);
|
|
api.route('/waitlist', waitlistRoutes);
|
|
api.route('/classes', classesRoutes);
|
|
api.route('/students', studentStatusRoutes);
|
|
api.route('/groups-risk', groupsRiskOverviewRoute);
|
|
api.route('/attention', attentionRoutes);
|
|
api.route('/people', peopleRoutes);
|
|
api.route('/student-portal', studentPortalRoutes);
|
|
|
|
app.notFound((c) => {
|
|
return problemJson(c, notFoundProblem(c.req.path));
|
|
});
|
|
|
|
app.onError((error, c) => {
|
|
logger.error({ error, path: c.req.path }, 'Unhandled request error');
|
|
return problemJson(c, internalServerErrorProblem(c.req.path));
|
|
});
|
|
|
|
export default app; |