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:
@@ -12,6 +12,11 @@ const db = {
|
||||
create: mock(),
|
||||
delete: mock(),
|
||||
},
|
||||
person: {
|
||||
findFirst: mock(),
|
||||
create: mock(),
|
||||
deleteMany: mock(),
|
||||
},
|
||||
groupWaitlistEntry: {
|
||||
findMany: mock(),
|
||||
findFirst: mock(),
|
||||
@@ -70,12 +75,16 @@ const waitlistEntry = (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,
|
||||
},
|
||||
createdAt: new Date('2026-09-18T10:00:00.000Z'),
|
||||
updatedAt: new Date('2026-09-18T10:00:00.000Z'),
|
||||
...overrides,
|
||||
@@ -94,6 +103,9 @@ function makeApp(userValue: unknown) {
|
||||
describe('group waitlist management', () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
// The phone is nobody the teacher has yet: promoting creates the person.
|
||||
prisma.person.findFirst.mockResolvedValue(null);
|
||||
prisma.person.create.mockResolvedValue({ id: 'person-1' } as never);
|
||||
});
|
||||
|
||||
describe('GET /groups/:groupId/waitlist', () => {
|
||||
@@ -146,7 +158,12 @@ describe('group waitlist management', () => {
|
||||
const data = await res.json();
|
||||
expect(data.attendee.fullName).toBe('Martín Gómez');
|
||||
expect(prisma.attendee.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({ groupId: 'group-1', fullName: 'Martín Gómez', phone: '+5491133445566' }),
|
||||
data: { groupId: 'group-1', personId: 'person-1' },
|
||||
include: { person: { select: expect.any(Object) } },
|
||||
});
|
||||
expect(prisma.person.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({ createdById: teacherId, fullName: 'Martín Gómez', phone: '+5491133445566' }),
|
||||
select: { id: true },
|
||||
});
|
||||
expect(prisma.groupWaitlistEntry.delete).toHaveBeenCalledWith({ where: { id: 'wl-1' } });
|
||||
});
|
||||
@@ -167,10 +184,17 @@ describe('group waitlist management', () => {
|
||||
expect(prisma.groupWaitlistEntry.delete).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects with 409 when the phone already belongs to an attendee', async () => {
|
||||
it('rejects with 409 when the person is already a member of the group', async () => {
|
||||
prisma.group.findUnique.mockResolvedValue(mockGroup as never);
|
||||
prisma.groupWaitlistEntry.findFirst.mockResolvedValue(waitlistEntry() as never);
|
||||
prisma.attendee.count.mockResolvedValue(5);
|
||||
prisma.person.findFirst.mockResolvedValue({
|
||||
id: 'person-1',
|
||||
fullName: 'Martín Gómez',
|
||||
email: null,
|
||||
phone: '+5491133445566',
|
||||
attendees: [{ id: 'att-existing', groupId: 'group-1', status: 'ACTIVE', group: { name: 'Pintura' } }],
|
||||
} as never);
|
||||
prisma.attendee.findFirst.mockResolvedValue({ id: 'att-existing' } as never);
|
||||
|
||||
const res = await makeApp({ id: teacherId }).request('/groups/group-1/waitlist/wl-1/promote', {
|
||||
@@ -227,7 +251,8 @@ describe('group waitlist management', () => {
|
||||
expect(prisma.group.findUnique).toHaveBeenLastCalledWith({ where: { id: 'group-2' } });
|
||||
expect(prisma.attendee.count).toHaveBeenCalledWith({ where: { groupId: 'group-2', status: 'ACTIVE' } });
|
||||
expect(prisma.attendee.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({ groupId: 'group-2', fullName: 'Martín Gómez' }),
|
||||
data: { groupId: 'group-2', personId: 'person-1' },
|
||||
include: { person: { select: expect.any(Object) } },
|
||||
});
|
||||
expect(prisma.groupWaitlistEntry.delete).toHaveBeenCalledWith({ where: { id: 'wl-1' } });
|
||||
});
|
||||
@@ -325,6 +350,10 @@ describe('group waitlist management', () => {
|
||||
expect(body.removedAttendeeId).toBe('att-1');
|
||||
expect(body.promoted).toBeNull();
|
||||
expect(prisma.attendee.delete).toHaveBeenCalledWith({ where: { id: 'att-1' } });
|
||||
// Their last group: the person goes too (no-op if they are in others).
|
||||
expect(prisma.person.deleteMany).toHaveBeenCalledWith({
|
||||
where: { id: 'person-1', attendees: { none: {} } },
|
||||
});
|
||||
});
|
||||
|
||||
it('removes an attendee and promotes the first pending waitlist entry atomically', async () => {
|
||||
@@ -353,8 +382,9 @@ describe('group waitlist management', () => {
|
||||
expect(body.promoted).toMatchObject({ id: 'wl-1', fullName: 'Sofía Ruiz' });
|
||||
expect(prisma.attendee.delete).toHaveBeenCalledWith({ where: { id: 'att-1' } });
|
||||
expect(prisma.groupWaitlistEntry.delete).toHaveBeenCalledWith({ where: { id: 'wl-1' } });
|
||||
expect(prisma.attendee.create).toHaveBeenCalledWith({
|
||||
expect(prisma.person.create).toHaveBeenCalledWith({
|
||||
data: expect.objectContaining({ fullName: 'Sofía Ruiz', phone: '+5491133778899' }),
|
||||
select: { id: true },
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user