feat: un miembro puede pertenecer a más de un grupo

- 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>
This commit is contained in:
Jose Selesan
2026-11-03 09:46:37 -03:00
parent f1829fb5a9
commit d21e1c3730
84 changed files with 1981 additions and 423 deletions

View File

@@ -1,17 +1,37 @@
import type { AttendeeDetailDto, AttendeeDto, AttendeeListItem } from '@gruperly/shared';
export type AttendeeRecord = {
/* Contact data of the person behind an attendee (shared by all their groups). */
export const personContactSelect = {
id: true,
fullName: true,
email: true,
phone: true,
guardianName: true,
guardianPhone: true,
notes: true,
} as const;
/* `include` for any attendee query that ends up in `toAttendeeDto`. */
export const attendeeWithPerson = { person: { select: personContactSelect } } as const;
export type PersonContactRecord = {
id: string;
groupId: string;
fullName: string;
email: string | null;
phone: string | null;
guardianName: string | null;
guardianPhone: string | null;
notes: string | null;
};
export type AttendeeRecord = {
id: string;
groupId: string;
personId: string;
notifyToken?: string | null;
createdAt: Date;
updatedAt: Date;
person: PersonContactRecord;
};
/** Listing item with the attendance and payment summary already resolved. */
@@ -25,18 +45,20 @@ export type AttendeeListItemRecord = AttendeeRecord & {
export type AttendeeDetailRecord = AttendeeRecord & {
payments: AttendeeListItemRecord['payments'];
otherGroups: AttendeeDetailDto['otherGroups'];
};
export function toAttendeeDto(record: AttendeeRecord): AttendeeDto {
return {
id: record.id,
groupId: record.groupId,
fullName: record.fullName,
email: record.email,
phone: record.phone,
guardianName: record.guardianName,
guardianPhone: record.guardianPhone,
notes: record.notes,
personId: record.personId,
fullName: record.person.fullName,
email: record.person.email,
phone: record.person.phone,
guardianName: record.person.guardianName,
guardianPhone: record.person.guardianPhone,
notes: record.person.notes,
notifyToken: record.notifyToken ?? null,
createdAt: record.createdAt.toISOString(),
updatedAt: record.updatedAt.toISOString(),
@@ -68,6 +90,7 @@ export function toAttendeeDetailDto(record: AttendeeDetailRecord): AttendeeDetai
return {
...toAttendeeDto(record),
payment: pickRelevantPayment(record.payments),
otherGroups: record.otherGroups,
};
}
@@ -91,3 +114,13 @@ export function normalizePhone(rawPhone: string): string {
const digitsOnly = trimmed.replace(/\D/g, '');
return hasPlus ? `+${digitsOnly}` : digitsOnly;
}
/* For queries that select a few person fields next to the attendee's: turns
`{ id, person: { fullName } }` into `{ id, fullName }`, so the code reading
flat rows stays as it was. */
export function flattenPerson<TRow extends { person: object }>(
row: TRow,
): Omit<TRow, 'person'> & TRow['person'] {
const { person, ...rest } = row;
return { ...rest, ...person };
}