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:
@@ -1,4 +1,5 @@
|
||||
import { z } from 'zod';
|
||||
import { attendeeStatusSchema } from './analytics.js';
|
||||
import { attendanceStatusSchema } from './attendance.js';
|
||||
import { createPageSchema, createPageSizeSchema, createPaginationSchema } from './pagination.js';
|
||||
import { paymentStatusSchema } from './payments.js';
|
||||
@@ -14,9 +15,12 @@ const paginationSchema = createPaginationSchema();
|
||||
HISTORY_SESSIONS_LIMIT classes separately. */
|
||||
export const RECENT_ATTENDANCE_LIMIT = 5;
|
||||
|
||||
/* An attendee is the membership of a person in one group. Contact data belongs
|
||||
to the person (shared by all their groups) and travels flattened here. */
|
||||
export const AttendeeDtoSchema = z.object({
|
||||
id: z.string(),
|
||||
groupId: z.string(),
|
||||
personId: z.string(),
|
||||
fullName: z.string(),
|
||||
email: z.string().nullable(),
|
||||
phone: z.string().nullable(),
|
||||
@@ -59,8 +63,19 @@ export const AttendeePaymentSummarySchema = z.object({
|
||||
});
|
||||
export type AttendeePaymentSummary = z.output<typeof AttendeePaymentSummarySchema>;
|
||||
|
||||
/** Another group of the teacher the same person is in. */
|
||||
export const PersonMembershipSchema = z.object({
|
||||
attendeeId: z.string(),
|
||||
groupId: z.string(),
|
||||
groupName: z.string(),
|
||||
status: attendeeStatusSchema,
|
||||
});
|
||||
export type PersonMembership = z.output<typeof PersonMembershipSchema>;
|
||||
|
||||
export const AttendeeDetailDtoSchema = AttendeeDtoSchema.extend({
|
||||
payment: AttendeePaymentSummarySchema.nullable(),
|
||||
/** The person's memberships in the teacher's other groups. */
|
||||
otherGroups: z.array(PersonMembershipSchema),
|
||||
});
|
||||
export type AttendeeDetailDto = z.output<typeof AttendeeDetailDtoSchema>;
|
||||
|
||||
@@ -106,6 +121,9 @@ export const CreateAttendeeSchema = z.object({
|
||||
phone: z.string().trim().min(6, 'Ingresa un número de teléfono válido'),
|
||||
email: z.string().trim().email('Email inválido').optional().or(z.literal('')),
|
||||
notes: z.string().trim().optional(),
|
||||
/* Adds an existing person of the teacher (found by phone) instead of creating
|
||||
a new one: the name/email fields are ignored then. */
|
||||
personId: z.string().min(1).optional(),
|
||||
});
|
||||
export type CreateAttendee = z.output<typeof CreateAttendeeSchema>;
|
||||
|
||||
@@ -154,6 +172,8 @@ export type BulkCreateAttendees = z.output<typeof BulkCreateAttendeesSchema>;
|
||||
export const BulkCreateAttendeesResultSchema = z.object({
|
||||
totalProcessed: z.number().int(),
|
||||
createdCount: z.number().int(),
|
||||
/** Rows whose phone was already a person of the teacher: added to this group as that person. */
|
||||
linkedCount: z.number().int(),
|
||||
duplicatesCount: z.number().int(),
|
||||
invalidCount: z.number().int(),
|
||||
message: z.string(),
|
||||
@@ -175,6 +195,30 @@ export const MoveAttendeeSchema = z.object({
|
||||
});
|
||||
export type MoveAttendee = z.output<typeof MoveAttendeeSchema>;
|
||||
|
||||
// Adds the same person to another group of the teacher, keeping this one.
|
||||
export const AddAttendeeToGroupSchema = z.object({
|
||||
targetGroupId: z.string().min(1),
|
||||
});
|
||||
export type AddAttendeeToGroup = z.output<typeof AddAttendeeToGroupSchema>;
|
||||
|
||||
/* "Ya existe esta persona": what the add form shows when the phone is already
|
||||
one of the teacher's people (`GET /people/lookup?groupId=&phone=`). The
|
||||
group says whose people: its owner's. */
|
||||
export const PersonLookupQuerySchema = z.object({
|
||||
groupId: z.string().min(1),
|
||||
phone: z.string().trim().min(6),
|
||||
});
|
||||
export type PersonLookupQuery = z.output<typeof PersonLookupQuerySchema>;
|
||||
|
||||
export const PersonSummarySchema = z.object({
|
||||
id: z.string(),
|
||||
fullName: z.string(),
|
||||
email: z.string().nullable(),
|
||||
phone: z.string().nullable(),
|
||||
groups: z.array(PersonMembershipSchema),
|
||||
});
|
||||
export type PersonSummary = z.output<typeof PersonSummarySchema>;
|
||||
|
||||
export const PromoteGroupWaitlistEntryResultSchema = z.object({
|
||||
attendee: AttendeeDtoSchema,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user