Builds on the existing Order model + SSE dashboard (no parallel system).
Model: extend Order.items JSON to {productId,name,qty,note?,price?} and add
Order.note (general note) — migration 0005.
Public menu (only when orders are enabled):
- Add button on every dish in BOTH card and list views
- Dedicated floating cart FAB with an item-count badge
- Cart sheet: per-line qty +/- (0 removes), per-item note, per-line subtotal +
total, a general order note, and required table number; confirm posts to the
existing POST /order, shows a confirmation toast and clears the cart
- Cart lives in client state only (no localStorage)
Admin Orders tab:
- Shows per-item notes and the general note
- Edit mode: adjust quantities, edit per-item and general notes, and ADD dishes
via a searchable dropdown over the restaurant's menu; saves through an extended
PATCH /orders/[id] that updates items/note and broadcasts a new 'order-edit' SSE
event so the dashboard updates live. Table number and timer (createdAt) preserved
order POST and PATCH sanitize/clamp incoming items (public + admin input).
i18n: cart/notes/total/confirm/search labels in es/en at parity. Glassmorphism,
mobile-first and safe areas preserved.
Endpoints/models: no new routes — POST /api/[slug]/order and PATCH
/api/[slug]/orders/[id] extended; Order model extended (items shape + note column,
migration 0005); new SSE event type 'order-edit'.
Verified: build passes; 5 migrations apply; order create persists qty/notes/price;
admin edit adds dishes + notes keeping table/timer; unauth edit 401.
105 lines
3.7 KiB
Plaintext
105 lines
3.7 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)
|
|
showMacros Boolean @default(false) // when false, the public menu hides all macro layers
|
|
|
|
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)
|
|
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? }]
|
|
note String? // general note for the whole order
|
|
status String @default("active") // active | completed
|
|
createdAt DateTime @default(now())
|
|
completedAt DateTime?
|
|
|
|
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([restaurantId, status])
|
|
}
|