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

@@ -56,12 +56,16 @@ const targetGroup = (overrides: Record<string, unknown> = {}) =>
const attendee = (overrides: Record<string, unknown> = {}) => ({
id: 'att-1',
groupId: 'group-1',
fullName: 'Martín Gómez',
phone: '+5491133445566',
email: null,
guardianName: null,
guardianPhone: null,
notes: null,
personId: 'person-1',
person: {
id: 'person-1',
fullName: 'Martín Gómez',
phone: '+5491133445566',
email: null,
guardianName: null,
guardianPhone: null,
notes: null,
},
notifyToken: 'notify-1',
status: 'ACTIVE',
createdAt: new Date('2026-09-18T10:00:00.000Z'),
@@ -105,6 +109,7 @@ describe('POST /groups/:groupId/attendees/:attendeeId/move', () => {
expect(prisma.attendee.update).toHaveBeenCalledWith({
where: { id: 'att-1' },
data: { groupId: 'group-2' },
include: { person: { select: expect.any(Object) } },
});
const futureOldClasses = {
classSession: { groupId: 'group-1', startsAt: { gt: expect.any(Date) } },
@@ -169,7 +174,7 @@ describe('POST /groups/:groupId/attendees/:attendeeId/move', () => {
expect(prisma.absenceNotice.updateMany).not.toHaveBeenCalled();
});
it('rejects with 409 when the phone already belongs to a member of the target group', async () => {
it('rejects with 409 when the person is already a member of the target group', async () => {
prisma.group.findUnique
.mockResolvedValueOnce(group() as never)
.mockResolvedValueOnce(targetGroup() as never);
@@ -182,6 +187,10 @@ describe('POST /groups/:groupId/attendees/:attendeeId/move', () => {
expect(res.status).toBe(409);
expect((await res.json()).code).toBe('attendee_already_registered');
expect(prisma.attendee.findFirst).toHaveBeenLastCalledWith({
where: { groupId: 'group-2', personId: 'person-1' },
select: { id: true },
});
expect(prisma.attendee.update).not.toHaveBeenCalled();
});