Files
smartmenu-collina/prisma/schema.prisma
T
Jorem Juárez 1dfdecb262 Add collaborative split-bill by table
Built on the existing Order/SSE system (no parallel system). Model choice: each
Order is one subaccount; a table account is the set of active orders sharing a
tableNumber with split=true. This reuses table grouping, the SSE events, GET
/orders, retention pruning, and the dashboard with minimal change.

Model (migration 0010): Order.split/subaccountName/paid, Restaurant.splitEnabled,
OrderItem.addedAt (for intermediate-item timing).

Endpoints (public): GET table-status (none/normal/split), POST split/join
(creates/joins; converts a normal table to split non-destructively — existing
orders flagged split=true as an unnamed 'table' subaccount, items kept; name
collisions get a numeric suffix), POST split/sync (diner updates own subaccount),
GET split/summary (table total + count, NO per-subaccount item detail). Editor
PATCH /orders/[id] gains a paid toggle; settings gains splitEnabled.

Public UI: Split FAB (only when splitEnabled && orders on), join/convert modal,
diner subaccount view (own items + own subtotal + table total only), and detection
in the normal cart that offers to join when the table is already split.

Admin (OrdersTab): split tables grouped and broken down by subaccount (name, items,
subtotal, paid badge/toggle) + table total + complete-table; live via SSE.

Block 7 — modification notice + dual timer: order-edit highlights the card as
'Modificada' (ring + badge, dismiss on click; self-edits suppressed); the main
table timer keeps running from createdAt (never reset on edit) and drives the
green→amber→red color, while intermediate items show 'added X ago' from addedAt.

i18n es/en at parity. Glassmorphism, mobile-first, safe areas preserved.

Verified end-to-end (migration 0010 applies; build passes; all i18n present):
1 split button hidden when splitEnabled off (🧾 count 0→1);
2 join+sync creates Ana subaccount w/ 2 items;
3 table-status reports split for table 5;
4 Beto joins → 2 subaccounts, summary exposes total+count only (no item detail);
5 dashboard breakdown Ana $200 / Beto $50 / total $250, mark paid persists + SSE order-edit fires;
6 normal table 3 converts to split keeping its items (becomes '(table)' subaccount + new named one);
7 adding an item 10 min later keeps createdAt (main timer ~10m) and stamps the new item's addedAt recent.
2026-06-15 18:43:57 -06:00

117 lines
4.6 KiB
Plaintext

generator client {
provider = "prisma-client-js"
// native = host platform (builder/runner are both node:20-alpine = musl).
// The explicit musl target guards the runtime engine in the final image.
binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
model Restaurant {
id String @id @default(cuid())
slug String @unique
name String
editorSecret String
username String
hashedPassword String
palette Json @default("{}")
qrConfig Json @default("{}") // artistic QR styling (qr-code-styling config)
ordersEnabled Boolean @default(false)
splitEnabled Boolean @default(false) // enables collaborative split-by-table accounts
orderRetentionHours Int @default(24) // completed orders older than this are pruned on read
showMacros Boolean @default(false) // when false, the public menu hides all macro layers
pairings Json @default("{}") // precomputed cart suggestions { productId: [productId] }
bannerImage String? // wide brand banner (uploaded)
profileImage String? // circular logo/avatar (uploaded)
socialLinks Json @default("[]") // [{ platform, url }]
defaultLocale String @default("es")
active Boolean @default(true)
publishedVersionId String? @unique
createdAt DateTime @default(now())
publishedVersion MenuVersion? @relation("PublishedVersion", fields: [publishedVersionId], references: [id])
versions MenuVersion[] @relation("RestaurantVersions")
sections Section[]
products Product[]
orders Order[]
}
// Versioning system: a published snapshot of the whole menu.
model MenuVersion {
id String @id @default(cuid())
restaurantId String
versionName String
snapshot Json
publishedAt DateTime @default(now())
createdBy String?
restaurant Restaurant @relation("RestaurantVersions", fields: [restaurantId], references: [id], onDelete: Cascade)
publishedFor Restaurant? @relation("PublishedVersion")
@@index([restaurantId])
}
// Working DRAFT (not what the public sees).
model Section {
id String @id @default(cuid())
restaurantId String
name Json // { es, en }
order Int @default(0)
showMacros Boolean @default(true) // per-section override; only applies when Restaurant.showMacros is on
createdAt DateTime @default(now())
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
products Product[]
@@index([restaurantId])
}
// Working DRAFT product.
model Product {
id String @id @default(cuid())
sectionId String
restaurantId String
name Json // { es, en }
description Json @default("{}") // { es, en }
price Decimal @default(0) @db.Decimal(10, 2)
order Int @default(0)
isActive Boolean @default(true)
allergens String[] @default([])
dietTags String[] @default([])
macros Json @default("{}") // { protein, carbs, sugar, fat, fiber, kcal }
media Json @default("[]") // [{ type, path, order }]
translationStatus Json @default("{}") // { en: auto|reviewed }
aiEstimated Json @default("{}") // { macros: bool, allergens: bool } — flags AI-inferred data to verify
createdAt DateTime @default(now())
section Section @relation(fields: [sectionId], references: [id], onDelete: Cascade)
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
@@index([restaurantId])
@@index([sectionId])
}
model Order {
id String @id @default(cuid())
restaurantId String
tableNumber Int
items Json // [{ productId, name, qty, note?, price?, addedAt? }]
note String? // general note for the whole order
status String @default("active") // active | completed
// Split: each Order is one subaccount of a table. A table is "in split" when
// any active order for that tableNumber has split=true. Reuses table grouping.
split Boolean @default(false)
subaccountName String? // diner name for the subaccount (null = unnamed/"table")
paid Boolean @default(false) // restaurant marks a subaccount as paid
createdAt DateTime @default(now())
completedAt DateTime?
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
@@index([restaurantId, status])
}