- 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>
67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import type { PrismaClient } from '@generated/prisma/client';
|
|
import type { AttendeeDetailDto, ProblemDetails, Result } from '@gruperly/shared';
|
|
import { err, ok } from '@gruperly/shared';
|
|
import { notFoundResourceProblem } from '@/http/problem-builders';
|
|
import prisma from '@/lib/prisma';
|
|
import { findGroupForUser } from '@/modules/group-waitlist/lib/helpers';
|
|
import { personMembershipsSelect, toMemberships } from '@/modules/people/lib/people';
|
|
import { personContactSelect, toAttendeeDetailDto } from '../../lib/helpers';
|
|
|
|
type GetAttendeeDeps = {
|
|
db?: Pick<PrismaClient, 'group' | 'attendee'>;
|
|
now?: () => Date;
|
|
};
|
|
|
|
export class GetAttendee {
|
|
constructor(private readonly deps: GetAttendeeDeps = {}) {}
|
|
|
|
async execute(
|
|
groupId: string,
|
|
attendeeId: string,
|
|
userId: string,
|
|
): Promise<Result<AttendeeDetailDto, ProblemDetails>> {
|
|
const db = this.deps.db ?? prisma;
|
|
|
|
const access = await findGroupForUser(db, groupId, userId);
|
|
if (!access.ok) {
|
|
return access;
|
|
}
|
|
|
|
const billingPeriod = currentMonthRange((this.deps.now ?? (() => new Date()))());
|
|
const attendee = await db.attendee.findFirst({
|
|
where: { id: attendeeId, groupId },
|
|
include: {
|
|
person: { select: { ...personContactSelect, ...personMembershipsSelect } },
|
|
payments: {
|
|
where: {
|
|
status: { not: 'CANCELLED' },
|
|
dueDate: { gte: billingPeriod.start, lt: billingPeriod.end },
|
|
},
|
|
orderBy: { dueDate: 'desc' },
|
|
take: 1,
|
|
select: { status: true, dueDate: true },
|
|
},
|
|
},
|
|
});
|
|
if (!attendee) {
|
|
return err(notFoundResourceProblem('Attendee', attendeeId));
|
|
}
|
|
|
|
const { attendees: memberships, ...person } = attendee.person;
|
|
return ok(
|
|
toAttendeeDetailDto({
|
|
...attendee,
|
|
person,
|
|
otherGroups: toMemberships(memberships.filter((membership) => membership.id !== attendee.id)),
|
|
}),
|
|
);
|
|
}
|
|
}
|
|
|
|
function currentMonthRange(now: Date) {
|
|
return {
|
|
start: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1)),
|
|
end: new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + 1, 1)),
|
|
};
|
|
}
|