Import a menu from PDF, photo, Excel/CSV, web link, or pasted text and turn it into draft sections + products with Claude. - Product.aiEstimated JSON flags AI-inferred macros/allergens (migration 0002) - POST /api/[slug]/import: resolves the source (vision via Sonnet for PDF/photo, Haiku for text/CSV/XLSX/web), extracts structured JSON for review only - POST /api/[slug]/import/apply: writes to the draft in add or replace mode, preserving aiEstimated flags; replace wipes the draft first - Editor: 'Cargar menú' button + glass ImportModal (method -> review -> add/replace), 'Estimado por IA — verifica' badges, verification disclaimer; ProductEditor shows the badge and clears the flag when the value is edited - Reuses anthropic.ts, upload/guard, shared extractJson (moved to lib/json.ts) - i18n labels (es/en); adds xlsx dependency for spreadsheet parsing Verified: build passes; migration applies; apply add/replace persist correctly with aiEstimated; extract validation + auth guard behave as expected.
101 lines
3.4 KiB
Plaintext
101 lines
3.4 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("{}")
|
|
ordersEnabled Boolean @default(false)
|
|
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 }]
|
|
status String @default("active") // active | completed
|
|
createdAt DateTime @default(now())
|
|
completedAt DateTime?
|
|
|
|
restaurant Restaurant @relation(fields: [restaurantId], references: [id], onDelete: Cascade)
|
|
|
|
@@index([restaurantId, status])
|
|
}
|