Files
gruperly/apps/backend/prisma/models/domain.prisma
Jose Selesan 21a4c69f38 feat(mp): add Mercado Pago reauthorization notice and status card components
- Implemented MpReauthNotice component to notify users when reauthorization is needed.
- Created MpStatusCard component to display the current status of the Mercado Pago account.
- Added utility functions and constants for handling Mercado Pago status and messages.
- Introduced hooks for managing the connection and disconnection of Mercado Pago accounts.
- Developed a disconnect confirmation modal for user actions.
- Added tests for the new functionality and utility functions.
- Defined schemas for Mercado Pago account status and callback reasons in shared package.
2026-10-07 12:00:38 -03:00

231 lines
7.8 KiB
Plaintext

// Domain models
model Group {
id String @id @default(cuid())
name String
description String?
days WeekDay[]
time String?
capacity Int?
price Decimal? @db.Decimal(10, 2)
billingType BillingType? @map("billing_type")
dueDay Int? @map("due_day")
inviteToken String? @unique(map: "groups_inviteToken_key") @map("invite_token")
createdById String @map("created_by_id")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
owner User @relation("OwnerGroups", fields: [createdById], references: [id], onDelete: Cascade, map: "groups_createdById_fkey")
members GroupMember[]
attendees Attendee[]
payments Payment[]
waitlist GroupWaitlistEntry[]
preRegistrations GroupPreRegistration[]
classSessions ClassSession[]
@@map("groups")
}
enum WeekDay {
MONDAY
TUESDAY
WEDNESDAY
THURSDAY
FRIDAY
SATURDAY
SUNDAY
}
enum BillingType {
MONTHLY
PER_CLASS
}
model GroupMember {
id String @id @default(cuid())
groupId String @map("group_id")
userId String @map("user_id")
role Role @default(MEMBER) // OWNER, ADMIN, MEMBER
joinedAt DateTime @default(now()) @map("joined_at")
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade, map: "group_members_groupId_fkey")
user User @relation(fields: [userId], references: [id], onDelete: Cascade, map: "group_members_userId_fkey")
@@unique([groupId, userId], map: "group_members_groupId_userId_key")
@@map("group_members")
}
enum Role {
OWNER
ADMIN
MEMBER
}
enum AttendeeStatus {
ACTIVE
PAUSED
DROPPED
}
model Attendee {
id String @id @default(cuid())
groupId String @map("group_id")
fullName String @map("full_name")
email String?
phone String?
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")
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade, map: "attendees_groupId_fkey")
payments Payment[]
attendances Attendance[]
slotReleases SlotRelease[]
@@index([groupId], map: "attendees_groupId_idx")
@@map("attendees")
}
model Payment {
id String @id @default(cuid())
groupId String @map("group_id")
attendeeId String @map("attendee_id")
amount Decimal @db.Decimal(10, 2)
currency String @default("MXN")
status PaymentStatus @default(PENDING) // PENDING, PAID, OVERDUE, CANCELLED
dueDate DateTime @map("due_date")
paidAt DateTime? @map("paid_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade, map: "payments_groupId_fkey")
attendee Attendee @relation(fields: [attendeeId], references: [id], onDelete: Cascade, map: "payments_attendeeId_fkey")
@@index([groupId], map: "payments_groupId_idx")
@@index([attendeeId], map: "payments_attendeeId_idx")
@@map("payments")
}
enum PaymentStatus {
PENDING
PAID
OVERDUE
CANCELLED
}
model WaitlistEntry {
id String @id @default(cuid())
email String
name String?
status WaitlistStatus @default(PENDING) // PENDING, INVITED, JOINED, DECLINED
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
userId String? @unique(map: "waitlist_entries_userId_key") @map("user_id")
user User? @relation(fields: [userId], references: [id], onDelete: SetNull, map: "waitlist_entries_userId_fkey")
@@unique([email])
@@map("waitlist_entries")
}
model GroupWaitlistEntry {
id String @id @default(cuid())
groupId String @map("group_id")
fullName String @map("full_name")
phone String
email String?
notes String?
status WaitlistStatus @default(PENDING) // PENDING, INVITED, JOINED, DECLINED
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade, map: "group_waitlist_entries_groupId_fkey")
@@unique([groupId, phone], map: "group_waitlist_entries_groupId_phone_key")
@@index([groupId], map: "group_waitlist_entries_groupId_idx")
@@map("group_waitlist_entries")
}
enum WaitlistStatus {
PENDING
INVITED
JOINED
DECLINED
}
enum PreRegistrationStatus {
PENDING
APPROVED
REJECTED
}
model GroupPreRegistration {
id String @id @default(cuid())
groupId String @map("group_id")
fullName String @map("full_name")
phone String
email String?
status PreRegistrationStatus @default(PENDING)
reviewedAt DateTime? @map("reviewed_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade, map: "group_pre_registrations_groupId_fkey")
@@unique([groupId, phone], map: "group_pre_registrations_groupId_phone_key")
@@index([groupId], map: "group_pre_registrations_groupId_idx")
@@map("group_pre_registrations")
}
enum MpAccountStatus {
ACTIVE
REQUIRES_REAUTH
REVOKED
}
// Mercado Pago account linked by a teacher through OAuth (Authorization Code + PKCE).
// Tokens are stored encrypted (AES-256-GCM); there is a single active account per
// teacher and a Mercado Pago user cannot be linked to two teachers.
model MpAccount {
id String @id @default(cuid())
ownerId String @unique(map: "mp_accounts_ownerId_key") @map("owner_id")
mpUserId String @unique(map: "mp_accounts_mpUserId_key") @map("mp_user_id")
accessTokenEnc String @map("access_token_enc")
refreshTokenEnc String @map("refresh_token_enc")
expiresAt DateTime @map("expires_at")
scope String?
liveMode Boolean @default(false) @map("live_mode")
status MpAccountStatus @default(ACTIVE)
connectedAt DateTime @default(now()) @map("connected_at")
createdAt DateTime @default(now()) @map("created_at")
updatedAt DateTime @updatedAt @map("updated_at")
owner User @relation(fields: [ownerId], references: [id], onDelete: Cascade, map: "mp_accounts_ownerId_fkey")
// The daily refresh job looks for ACTIVE accounts expiring within 30 days.
@@index([status, expiresAt], map: "mp_accounts_status_expiresAt_idx")
@@map("mp_accounts")
}
// Pending OAuth authorization: the `state` sent to Mercado Pago plus the PKCE
// `code_verifier`. The `state` is the primary key because consuming it (deleting
// the row) is what makes it single use.
model MpOAuthState {
state String @id
ownerId String @map("owner_id")
codeVerifier String @map("code_verifier")
// Constrained to 'onboarding' | 'settings'; decides where the callback lands.
returnTo String @map("return_to")
expiresAt DateTime @map("expires_at")
createdAt DateTime @default(now()) @map("created_at")
// Expired rows are swept on every new authorization request.
@@index([expiresAt], map: "mp_oauth_states_expiresAt_idx")
@@map("mp_oauth_states")
}