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:
@@ -5,7 +5,7 @@ import { conflictProblem, notFoundResourceProblem } from '@/http/problem-builder
|
||||
import { default as prisma, UnitOfWork } from '@/lib/prisma';
|
||||
import { findGroupOwnedByUser } from '@/modules/group-waitlist/lib/helpers';
|
||||
import { checkCanJoinGroup } from '@/modules/group-waitlist/lib/promote';
|
||||
import { type AttendeeRecord, toAttendeeDto } from '../../lib/helpers';
|
||||
import { attendeeWithPerson, toAttendeeDto } from '../../lib/helpers';
|
||||
|
||||
type MoveAttendeeDeps = {
|
||||
db?: Pick<PrismaClient, 'group' | 'attendee'>;
|
||||
@@ -54,7 +54,7 @@ export class MoveAttendee {
|
||||
|
||||
return unitOfWork.executeResult(
|
||||
async (tx: Prisma.TransactionClient): Promise<Result<AttendeeDto, ProblemDetails>> => {
|
||||
const canJoin = await checkCanJoinGroup(tx, targetResult.value, attendee.phone);
|
||||
const canJoin = await checkCanJoinGroup(tx, targetResult.value, attendee.personId);
|
||||
if (!canJoin.ok) return canJoin;
|
||||
|
||||
const futureOldClasses = { classSession: { groupId, startsAt: { gt: now } } };
|
||||
@@ -68,8 +68,9 @@ export class MoveAttendee {
|
||||
const moved = await tx.attendee.update({
|
||||
where: { id: attendeeId },
|
||||
data: { groupId: targetGroupId },
|
||||
include: attendeeWithPerson,
|
||||
});
|
||||
return ok(toAttendeeDto(moved as unknown as AttendeeRecord));
|
||||
return ok(toAttendeeDto(moved));
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user