Files
gruperly/apps/backend/prisma/models/auth.prisma
Jose Selesan ac98495a6e feat(payments): automatic monthly charges with combined links per payer
- Teacher picks a day of the month in Settings; an hourly job creates the
  fees of all monthly groups on that day in the teacher's time zone
  (one run per teacher and month, partial unique index per attendee/period).
- One Mercado Pago link per payer (PaymentCheckout): the adult in charge
  bundles their kids and their own fees; external_reference chk_<id>,
  dedicated webhook and reconciliation mark every fee PAID at once.
- Person.payWithMercadoPago toggle (default on): off creates the fee
  without a link so the student pays by transfer.
- A fee paid some other way supersedes its combined link and expires the
  preference; renewing rebuilds the combined link or a single one.
- Optional WhatsApp delivery (PAYMENT_LINK kind, new Kapso template);
  weekly reminders now go once per combined link.
- Web: auto charge settings card, per-student toggle, combined link label
  in Cobros and "Pay all" in the student app, in the four locales.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 15:08:48 -03:00

158 lines
5.9 KiB
Plaintext

// Auth (Better Auth) - required tables
model User {
id String @id @default(cuid())
name String
email String @unique
emailVerified Boolean @default(false) @map("email_verified")
image String?
onboardingCompleted Boolean @default(false) @map("onboarding_completed")
country String? @map("country_code")
// UI language the person chose (es-AR, es-419, pt-BR, en); null follows the device.
locale String? @map("locale")
// When the professor chose Free or Pro in the onboarding (mandatory step).
planSelectedAt DateTime? @map("plan_selected_at")
// Bank transfer details shown to students when they report a payment.
transferAlias String? @map("transfer_alias")
transferHolder String? @map("transfer_holder")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
accounts Account[]
sessions Session[]
passkeys Passkey[]
groupsMember GroupMember[]
groupsOwner Group[] @relation("OwnerGroups")
orgMemberships Member[]
orgInvitations Invitation[] @relation("InvitedBy")
waitlist WaitlistEntry[]
mpAccount MpAccount?
whatsappAccount WhatsappAccount?
subscription BillingSubscription?
studentAccounts StudentAccount[] @relation("StudentAccountsCreated")
people Person[] @relation("OwnerPeople")
autoCharge AutoChargeSettings?
paymentRuns PaymentRun[]
checkouts PaymentCheckout[]
@@map("users")
}
model Account {
id String @id @default(cuid())
userId String @map("user_id")
providerId String @map("provider_id")
accountId String @map("account_id")
issuer String
accessToken String? @map("access_token")
refreshToken String? @map("refresh_token")
idToken String? @map("id_token")
accessTokenExpiresAt DateTime? @map("access_token_expires_at")
refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
scope String?
password String?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade, map: "accounts_userId_fkey")
@@unique([issuer, accountId], map: "accounts_issuer_accountId_key")
@@index([userId], map: "accounts_userId_idx")
@@map("accounts")
}
model Session {
id String @id @default(cuid())
userId String @map("user_id")
token String @unique
expiresAt DateTime @map("expires_at")
ipAddress String? @map("ip_address")
userAgent String? @map("user_agent")
activeOrganizationId String? @map("active_organization_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
user User @relation(fields: [userId], references: [id], onDelete: Cascade, map: "sessions_userId_fkey")
@@map("sessions")
}
model Verification {
id String @id @default(cuid())
identifier String
value String
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
@@unique([identifier, value])
@@map("verifications")
}
// Better Auth - Organization plugin
model Organization {
id String @id @default(cuid())
name String
slug String @unique
logo String?
metadata Json?
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
members Member[]
invitations Invitation[]
@@map("organizations")
}
model Member {
id String @id @default(cuid())
organizationId String @map("organization_id")
userId String @map("user_id")
role String @default("member")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, map: "members_organizationId_fkey")
user User @relation(fields: [userId], references: [id], onDelete: Cascade, map: "members_userId_fkey")
@@unique([organizationId, userId], map: "members_organizationId_userId_key")
@@map("members")
}
model Invitation {
id String @id @default(cuid())
organizationId String @map("organization_id")
email String
role String
status String @default("pending")
inviterId String @map("inviter_id")
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade, map: "invitations_organizationId_fkey")
inviter User @relation("InvitedBy", fields: [inviterId], references: [id], onDelete: Cascade, map: "invitations_inviterId_fkey")
@@index([organizationId], map: "invitations_organizationId_idx")
@@map("invitations")
}
// Better Auth - Passkey plugin
model Passkey {
id String @id @default(cuid())
name String?
publicKey String @map("public_key")
credentialID String @unique(map: "passkeys_credentialID_key") @map("credential_id")
userId String @map("user_id")
counter Int
deviceType String @map("device_type")
backedUp Boolean @map("backed_up")
transports String?
createdAt DateTime @default(now()) @map("created_at")
aaguid String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade, map: "passkeys_userId_fkey")
@@index([userId], map: "passkeys_userId_idx")
@@map("passkeys")
}