feat: make pantry items and meal plan entries user-scoped; update related services and controllers

This commit is contained in:
Nils-Johan Gynther
2026-04-22 18:38:04 +02:00
parent 44b4e7ad73
commit 4482129fca
6 changed files with 123 additions and 35 deletions
+12 -2
View File
@@ -23,6 +23,8 @@ model User {
ownedRecipes Recipe[] @relation("RecipeOwner")
sharedRecipes RecipeShare[]
ownedProducts Product[]
pantryItems PantryItem[]
mealPlanEntries MealPlanEntry[]
}
model Product {
@@ -160,10 +162,15 @@ model RecipeIngredient {
model PantryItem {
id Int @id @default(autoincrement())
productId Int @unique
userId Int
productId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([userId, productId])
@@index([userId])
}
model ReceiptAlias {
@@ -176,14 +183,17 @@ model ReceiptAlias {
model MealPlanEntry {
id Int @id @default(autoincrement())
userId Int
date DateTime @db.Date
recipe Recipe @relation(fields: [recipeId], references: [id], onDelete: Cascade)
recipeId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
servings Int?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([date])
@@unique([userId, date]) # Bara ett recept per dag och användare
@@index([userId])
@@index([date])
}