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:
@@ -28,6 +28,7 @@ model User {
|
||||
whatsappAccount WhatsappAccount?
|
||||
subscription BillingSubscription?
|
||||
studentAccounts StudentAccount[] @relation("StudentAccountsCreated")
|
||||
people Person[] @relation("OwnerPeople")
|
||||
|
||||
@@map("users")
|
||||
}
|
||||
|
||||
@@ -72,31 +72,55 @@ enum AttendeeStatus {
|
||||
DROPPED
|
||||
}
|
||||
|
||||
model Attendee {
|
||||
id String @id @default(cuid())
|
||||
groupId String @map("group_id")
|
||||
fullName String @map("full_name")
|
||||
// A person the teacher works with (student, or the guardian's child). Contact
|
||||
// data lives here once; `Attendee` is their membership in each group, so one
|
||||
// person can be in several groups of the same teacher. The phone is unique per
|
||||
// teacher through a hand-written partial index (`people_owner_phone_key`,
|
||||
// `WHERE phone IS NOT NULL`): Prisma does not model it.
|
||||
model Person {
|
||||
id String @id @default(cuid())
|
||||
createdById String @map("created_by_id")
|
||||
fullName String @map("full_name")
|
||||
email String?
|
||||
phone String?
|
||||
guardianName String? @map("guardian_name")
|
||||
guardianPhone String? @map("guardian_phone")
|
||||
guardianName String? @map("guardian_name")
|
||||
guardianPhone String? @map("guardian_phone")
|
||||
notes String?
|
||||
notifyToken String? @unique(map: "attendees_notifyToken_key") @default(cuid()) @map("notify_token")
|
||||
status AttendeeStatus @default(ACTIVE)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
owner User @relation("OwnerPeople", fields: [createdById], references: [id], onDelete: Cascade)
|
||||
attendees Attendee[]
|
||||
studentAccounts StudentAccountPerson[]
|
||||
|
||||
@@index([createdById])
|
||||
@@map("people")
|
||||
}
|
||||
|
||||
// Membership of a person in a group. Status, attendance, fees and the absence
|
||||
// link (`notifyToken`) are per group.
|
||||
model Attendee {
|
||||
id String @id @default(cuid())
|
||||
groupId String @map("group_id")
|
||||
personId String @map("person_id")
|
||||
notifyToken String? @unique(map: "attendees_notifyToken_key") @default(cuid()) @map("notify_token")
|
||||
status AttendeeStatus @default(ACTIVE)
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade, map: "attendees_groupId_fkey")
|
||||
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
|
||||
payments Payment[]
|
||||
attendances Attendance[]
|
||||
slotReleases SlotRelease[]
|
||||
outboundMessages OutboundMessage[]
|
||||
alertResolutions AttendeeAlertResolution[]
|
||||
studentAccounts StudentAccountAttendee[]
|
||||
absenceNotices AbsenceNotice[]
|
||||
reportedPayments ReportedPayment[]
|
||||
|
||||
@@unique([groupId, personId])
|
||||
@@index([groupId], map: "attendees_groupId_idx")
|
||||
@@index([personId])
|
||||
@@map("attendees")
|
||||
}
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ model StudentAccount {
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
|
||||
createdBy User @relation("StudentAccountsCreated", fields: [createdById], references: [id], onDelete: Cascade)
|
||||
attendees StudentAccountAttendee[]
|
||||
people StudentAccountPerson[]
|
||||
tokens StudentAccessToken[]
|
||||
sessions StudentSession[]
|
||||
passkeys StudentPasskey[]
|
||||
@@ -37,17 +37,20 @@ model StudentAccount {
|
||||
@@map("student_accounts")
|
||||
}
|
||||
|
||||
model StudentAccountAttendee {
|
||||
accountId String @map("account_id")
|
||||
attendeeId String @map("attendee_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
// The account is linked to people, not to memberships: it sees every group the
|
||||
// person is in (also the ones added later). A guardian may be linked to several
|
||||
// children (N:N).
|
||||
model StudentAccountPerson {
|
||||
accountId String @map("account_id")
|
||||
personId String @map("person_id")
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
|
||||
account StudentAccount @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
||||
attendee Attendee @relation(fields: [attendeeId], references: [id], onDelete: Cascade)
|
||||
account StudentAccount @relation(fields: [accountId], references: [id], onDelete: Cascade)
|
||||
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@id([accountId, attendeeId])
|
||||
@@index([attendeeId])
|
||||
@@map("student_account_attendees")
|
||||
@@id([accountId, personId])
|
||||
@@index([personId])
|
||||
@@map("student_account_people")
|
||||
}
|
||||
|
||||
enum StudentTokenKind {
|
||||
|
||||
Reference in New Issue
Block a user