feat: cambiar a un miembro de grupo

- `POST /groups/:gid/attendees/:aid/move` mueve al mismo attendee a otro
  grupo del profesor: conserva historial, cuotas (siguen del grupo anterior)
  y acceso a la app de alumnos. Cancela las faltas avisadas y libera lo
  reservado en clases futuras del grupo anterior.
- Cupo y teléfono duplicado se validan con `checkCanJoinGroup`, compartido
  con el paso desde la lista de espera.
- Ficha del miembro: "Cambiar de grupo" abre un diálogo con el selector de
  grupo destino y navega a la ficha en el grupo nuevo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jose Selesan
2026-11-02 16:21:32 -03:00
parent fc12ec3ae0
commit f1829fb5a9
11 changed files with 571 additions and 22 deletions

View File

@@ -23,11 +23,14 @@ export async function findFirstPendingWaitlistEntry(
return record as GroupWaitlistEntryRecord | null;
}
export async function promoteWaitlistEntryRecord(
db: PromoteDb,
/* Whether someone can join `group`: free capacity (ACTIVE members) and no
member there with the same phone. Shared by the waitlist promotion and the
member move between groups. */
export async function checkCanJoinGroup(
db: Pick<PrismaClient, 'attendee'>,
group: PromoteGroup,
entry: GroupWaitlistEntryRecord,
): Promise<Result<AttendeeDto, ProblemDetails>> {
phone: string | null,
): Promise<Result<void, ProblemDetails>> {
if (group.capacity !== null) {
const currentCount = await db.attendee.count({
where: { groupId: group.id, status: 'ACTIVE' },
@@ -37,16 +40,31 @@ export async function promoteWaitlistEntryRecord(
}
}
const existing = await db.attendee.findFirst({
where: { groupId: group.id, phone: entry.phone },
});
if (existing) {
return err(
conflictProblem({
detail: 'Ya existe un alumno registrado con este número de teléfono en este grupo.',
code: 'attendee_already_registered',
}),
);
if (phone) {
const existing = await db.attendee.findFirst({
where: { groupId: group.id, phone },
});
if (existing) {
return err(
conflictProblem({
detail: 'Ya existe un alumno registrado con este número de teléfono en este grupo.',
code: 'attendee_already_registered',
}),
);
}
}
return ok(undefined);
}
export async function promoteWaitlistEntryRecord(
db: PromoteDb,
group: PromoteGroup,
entry: GroupWaitlistEntryRecord,
): Promise<Result<AttendeeDto, ProblemDetails>> {
const canJoin = await checkCanJoinGroup(db, group, entry.phone);
if (!canJoin.ok) {
return canJoin;
}
const attendee = await db.attendee.create({