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

@@ -127,7 +127,7 @@ export class CancelStudentAbsence {
where: {
id: noticeId,
cancelledAt: null,
attendee: { status: { not: 'DROPPED' }, studentAccounts: { some: { accountId } } },
attendee: { status: { not: 'DROPPED' }, person: { studentAccounts: { some: { accountId } } } },
},
select: { id: true, attendeeId: true, classSessionId: true, classSession: { select: { startsAt: true } } },
});

View File

@@ -32,10 +32,20 @@ export class GetStudentLinkInfo {
account: {
select: {
name: true,
attendees: {
people: {
orderBy: { createdAt: 'asc' },
take: 1,
select: { attendee: { select: { group: { select: { name: true, owner: { select: { name: true } } } } } } },
select: {
person: {
select: {
attendees: {
orderBy: { createdAt: 'asc' },
take: 1,
select: { group: { select: { name: true, owner: { select: { name: true } } } } },
},
},
},
},
},
},
},
@@ -52,7 +62,7 @@ export class GetStudentLinkInfo {
return ok({ status: 'invalid' });
}
const group = row.account.attendees[0]?.attendee.group ?? null;
const group = row.account.people[0]?.person.attendees[0]?.group ?? null;
return ok({
status: 'valid',
kind: row.kind === 'INVITATION' ? 'invitation' : 'recovery',

View File

@@ -20,15 +20,21 @@ export class GetStudentMe {
pendingRecoveryEmail: true,
welcomedAt: true,
_count: { select: { passkeys: true } },
attendees: {
where: { attendee: { status: { not: 'DROPPED' } } },
// Linked people, and every group each of them is in.
people: {
orderBy: { createdAt: 'asc' },
select: {
attendee: {
person: {
select: {
id: true,
fullName: true,
group: { select: { id: true, name: true, owner: { select: { name: true } } } },
attendees: {
where: { status: { not: 'DROPPED' } },
orderBy: { createdAt: 'asc' },
select: {
id: true,
group: { select: { id: true, name: true, owner: { select: { name: true } } } },
},
},
},
},
},
@@ -46,13 +52,15 @@ export class GetStudentMe {
hasPasskey: account._count.passkeys > 0,
welcomed: account.welcomedAt !== null,
},
students: account.attendees.map(({ attendee }) => ({
attendeeId: attendee.id,
fullName: attendee.fullName,
groupId: attendee.group.id,
groupName: attendee.group.name,
teacherName: attendee.group.owner.name,
})),
students: account.people.flatMap(({ person }) =>
person.attendees.map((attendee) => ({
attendeeId: attendee.id,
fullName: person.fullName,
groupId: attendee.group.id,
groupName: attendee.group.name,
teacherName: attendee.group.owner.name,
})),
),
});
}
}

View File

@@ -1,36 +1,21 @@
import type { Prisma } from '@generated/prisma/client';
export type StudentAccessDb = {
studentAccountAttendee: Prisma.StudentAccountAttendeeDelegate;
};
/* The authorization rule of every student endpoint: only the attendees linked
to the session's account. Anything else is a 404 (we don't confirm ids). */
export async function linkedAttendeeIds(db: StudentAccessDb, accountId: string): Promise<string[]> {
const links = await db.studentAccountAttendee.findMany({
// A DROPPED attendee loses access; a PAUSED one keeps it.
where: { accountId, attendee: { status: { not: 'DROPPED' } } },
select: { attendeeId: true },
orderBy: { createdAt: 'asc' },
});
return links.map((link) => link.attendeeId);
}
export type LinkedAttendeeDb = { attendee: Prisma.AttendeeDelegate };
/* One attendee of the session, with what the student screens need from the
group. null for an attendee not linked to the account (or DROPPED): routes
answer 404, the same as for an id that doesn't exist. */
/* The authorization rule of every student endpoint: an attendee (membership)
of a person linked to the session's account, with what the student screens
need from the group. The account is linked to the person, so every group
they are in shows up. null for anything else (or DROPPED; PAUSED keeps
access): routes answer 404, the same as for an id that doesn't exist. */
export async function findLinkedAttendee(db: LinkedAttendeeDb, accountId: string, attendeeId: string) {
return db.attendee.findFirst({
where: {
id: attendeeId,
status: { not: 'DROPPED' },
studentAccounts: { some: { accountId } },
person: { studentAccounts: { some: { accountId } } },
},
select: {
id: true,
fullName: true,
groupId: true,
group: {
select: {