feat(backend): Abfuellungen und Produkte (Modul 23)
ProductsModule (GET/POST /products, GET/PATCH /products/:id) und BottlingModule (GET/POST /bottling-batches) mit transaktionaler Reduzierung der HoneyBatch-Restmenge beim Abfuellen; Ablehnung bei Abfuellmenge > verfuegbarer Menge. Neue Prisma-Modelle Product und BottlingBatch (Migration bottling_products).
This commit is contained in:
1 parent
8b7fd61c1c
commit
e82cae257b
17 files changed
+916
-2
No files matched your search
@@ -0,0 +1,59 @@
|
||||
-- CreateEnum
|
||||
CREATE TYPE "ProductStatus" AS ENUM ('ACTIVE', 'DISCONTINUED');
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "Product" (
|
||||
"id" TEXT NOT NULL,
|
||||
"name" TEXT NOT NULL,
|
||||
"description" TEXT,
|
||||
"sku" TEXT,
|
||||
"packagingSize" DOUBLE PRECISION,
|
||||
"weight" DOUBLE PRECISION,
|
||||
"salesUnit" TEXT,
|
||||
"status" "ProductStatus" NOT NULL DEFAULT 'ACTIVE',
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
"updatedAt" TIMESTAMP(3) NOT NULL,
|
||||
|
||||
CONSTRAINT "Product_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateTable
|
||||
CREATE TABLE "BottlingBatch" (
|
||||
"id" TEXT NOT NULL,
|
||||
"honeyBatchId" TEXT NOT NULL,
|
||||
"productId" TEXT,
|
||||
"date" TIMESTAMP(3) NOT NULL,
|
||||
"jarSize" DOUBLE PRECISION NOT NULL,
|
||||
"jarCount" INTEGER NOT NULL,
|
||||
"totalAmount" DOUBLE PRECISION NOT NULL,
|
||||
"bestBeforeDate" TIMESTAMP(3) NOT NULL,
|
||||
"lotNumber" TEXT NOT NULL,
|
||||
"userId" TEXT,
|
||||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
||||
CONSTRAINT "BottlingBatch_pkey" PRIMARY KEY ("id")
|
||||
);
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "Product_sku_key" ON "Product"("sku");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "Product_status_idx" ON "Product"("status");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "BottlingBatch_lotNumber_key" ON "BottlingBatch"("lotNumber");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "BottlingBatch_honeyBatchId_idx" ON "BottlingBatch"("honeyBatchId");
|
||||
|
||||
-- CreateIndex
|
||||
CREATE INDEX "BottlingBatch_productId_idx" ON "BottlingBatch"("productId");
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BottlingBatch" ADD CONSTRAINT "BottlingBatch_honeyBatchId_fkey" FOREIGN KEY ("honeyBatchId") REFERENCES "HoneyBatch"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BottlingBatch" ADD CONSTRAINT "BottlingBatch_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "BottlingBatch" ADD CONSTRAINT "BottlingBatch_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -49,6 +49,7 @@ model User {
|
||||
createdTasks Task[] @relation("TaskCreator")
|
||||
colonyMoves ColonyApiaryHistory[]
|
||||
auditLogs AuditLog[]
|
||||
bottlingBatches BottlingBatch[]
|
||||
|
||||
@@index([role])
|
||||
}
|
||||
@@ -528,7 +529,8 @@ model HoneyBatch {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
measurements HoneyMeasurement[]
|
||||
measurements HoneyMeasurement[]
|
||||
bottlingBatches BottlingBatch[]
|
||||
|
||||
@@index([status])
|
||||
@@index([extractionId])
|
||||
@@ -624,3 +626,49 @@ model StockMovement {
|
||||
|
||||
@@index([stockItemId, date])
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Abfüllungen und Produkte (Abschnitt 4.19, 4.20) – v1.x Modul 23
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
enum ProductStatus {
|
||||
ACTIVE
|
||||
DISCONTINUED
|
||||
}
|
||||
|
||||
model Product {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
description String?
|
||||
sku String? @unique
|
||||
packagingSize Float?
|
||||
weight Float?
|
||||
salesUnit String?
|
||||
status ProductStatus @default(ACTIVE)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
bottlingBatches BottlingBatch[]
|
||||
|
||||
@@index([status])
|
||||
}
|
||||
|
||||
model BottlingBatch {
|
||||
id String @id @default(cuid())
|
||||
honeyBatchId String
|
||||
honeyBatch HoneyBatch @relation(fields: [honeyBatchId], references: [id])
|
||||
productId String?
|
||||
product Product? @relation(fields: [productId], references: [id])
|
||||
date DateTime
|
||||
jarSize Float
|
||||
jarCount Int
|
||||
totalAmount Float
|
||||
bestBeforeDate DateTime
|
||||
lotNumber String @unique
|
||||
userId String?
|
||||
user User? @relation(fields: [userId], references: [id])
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([honeyBatchId])
|
||||
@@index([productId])
|
||||
}
|
||||
Reference in new issue
Block a user